Getting textbox value inside a Detailsview control - asp.net

I have a DetailsView control with a template field as follows:
<asp:TemplateField SortExpression="Title">
<ItemTemplate>
<asp:TextBox ID="txtMessageTitle" Text='<%# Bind("Title") %>' runat="server">
</asp:TextBox>
<asp:Button ID="btnUpdateTitle" runat="server" Text="Update"
CommandName="UpdateTitle" CommandArgument='<%# Bind("MessageID") %>' oncommand="btnUpdateCommand"/>
</ItemTemplate>
</asp:TemplateField>
The Details View is wrapped inside an UpdatePanel.
When the user clicks on btnUpdateButton I'd like to be able to retrieve the textbox (txtMessageTitle) value in code behind and by using CommandArgument of the button, update the appropriate MessageTitle in database. How can I retrieve the textbox value inside the DetailsView control from the Command event of my button?
Thanks.

use the following:
TextBox txtMessageTitle = detailsViewName.FindControl("txtMessageTitle") as TextBox;
string text = txtMessageTitle.Text;

Related

How to validate a textbox in a gridview of that specific row?

This is my aspx code:
<asp:TemplateField HeaderText="Enter_Quantity" >
<ItemTemplate>
<asp:TextBox ID ="TextBox1" runat="server" DataField="Total_Quantity" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please add a quantity"> </asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="Button7" runat="server" OnClick="Button7_Click" CommandArgument="Button7" CommandName="Select" Text="Add To Cart" CausesValidation ="true" />
</ItemTemplate>
</asp:TemplateField>
Kindly note that the Button is in every Gridview Row and also the textbox column is in every Gridview row.
The problem I'm facing is that when I keep the textbox empty and then click on the button. It is showing the error message "Please add a quantity". But it is showing it in every Gridview row. I want to show this error message for that specific GridView row.
How do I solve this ?
Can someone correct my aspx code ?
Set CauseValidation = "false".
It allows you to remove validation from specific control. Suppose you're using two buttons in your page but you want only one button to validate. But as per ASP rules all button will validate your form because of CausesValidation = true by default.

The ControlToValidate property of 'passwordCompare' cannot be blank

In my page I have repeater using which I dynamically generate two textboxes & I have one compare validator.
Now for this validator I want to set ControlTovalidate & ControlToCompare.
Id of both will come from two textboxes which are generated dynamically.
So while binding these textboxes to repeater I am setting both properties of validator But error comes as "The ControlToValidate property of 'passwordCompare' cannot be blank."
<asp:repeater id="repeater" runat="server" onitemdatabound="BoundProperty">
<itemtemplate>
<asp:panel id="panelProperty" runat="server" cssclass="prop">
<asp:textbox id="textboxOrg" runat="server" cssclass="edit" visible="false"/>
</asp:panel>
</itemtemplate>
</asp:repeater>
<asp:comparevalidator id="passwordCompare" runat="server" controltovalidate="" controltocompare="" errormessage="CompareValidator"></asp:comparevalidator>

Setting value to hidden field in gridview

I have gridview with textbox and one Update button outside gridview.
When i click on button whatever data changed in textbox those values will update in database.
Here is My Gridview templatefield which is having Textbox
<asp:TemplateField HeaderText="SeqNo" HeaderStyle-CssClass="gridViolation-status"
ItemStyle-CssClass="gridViolation-status" ItemStyle-HorizontalAlign="Center"
HeaderStyle-ForeColor="White" SortExpression="STATUS">
<ItemTemplate>
<asp:TextBox ID="txtSeqNo" runat="server" Width="40%" Text='<%# Bind("VIOLATIONCODESEQNO") %>'
onchange="SetValue()"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
and button outside gridview
<asp:Button ID="btnAdd" runat="server" Text="Update"
CssClass="submitbtn" OnClick="btnAdd_Click" />
I just need to update the value that is in textbox to database without using Foreach

Is it possible to add calendar control in boundfield inside grdview?

I have a problem in updating date using gridview. I want to add ajax control toolkit calendar control inside the gridview boundfield.
My sample gridview will look like this. these gridview details are from table.so, my Date column in BOUNDFIELD
when I update date, I need ajax calendar control should pop up to select date.
how to achieve this?
You need to use Item Templates......
Example :
<asp:TemplateField HeaderText="Is Active">
<ItemTemplate>
<asp:Label ID="lblIsActive" runat="server" Text='<%# Eval("YourValue").ToString() %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
// Add your item here (Like Textbox With Caleder control)
</EditItemTemplate>
</asp:TemplateField>

Get selected ID in asp.net listview bound to a hyperlink

I am new to asp.net, forgive my newbie question.
I have a listview which displays all item info (ItemID,Item name).
I bound the item name to a hyperlink control. now what i want to do is that when i click the hyperlink i want to get the ID and navigate the item detail page. i tried using selected index but it still returns null. here's my code.
On the listview itemTemplate code
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="ItemDetails.aspx"> <%# Eval("[ItemName]") %>
</asp:HyperLink>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[ItemID]") %>'/>
Please help.thanks in advance
Instead of Hyperlink, I used LinkButton in ItemTemplate If u want to pass the selectedId to the next page u can pass using Query String
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="120px">
<ItemTemplate>
<asp:LinkButton ID="lnk_ViewDetails" runat="server" Text='View Details' PostBackUrl='<%#"~/ViewDetailss.aspx?Id="+Eval("ID")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
If u want to encrypt querystring Please refer This Link

Resources