Cast the sender property to TextBox. Then cast the NamingContainer property to DataGridItem. You can now use the ItemIndex property on the DataKeys of the datagrid.
Cast the sender property to TextBox. Then cast the NamingContainer property to DataGridItem. You can now use the ItemIndex property on the DataKeys of the datagrid.
Hi sir, thx for your replied. But i not really what do your mean. Mind to desc more detail. Appreciated. TQ
Dim tb As TextBox = DirectCast(sender, TextBox)
Dim dgi As DataGridItem = DirectCast(tb.Parent.Parent, DataGridItem)
Dim pid As String = MyDataGrid.DataKeys(dgi.DataSetIndex).ToString()
Adding to that: If you replace tb.Parent.Parent by tb.NamingContainer, you have what MetalAsp.Net meant.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
kengkit
Member
120 Points
244 Posts
Getting datakeys while textchanged in datagrid.
Feb 28, 2012 05:35 PM|LINK
hi all, below is my datagrid. I have successfully obtained the value of txt_quantity but anyone can advice me how to get corresponding DataKey?
<asp:DataGrid ID="MyDataGrid" runat="server" DataKeyField="PID"> <Columns> <asp:TemplateColumn HeaderText="Qty."> <ItemTemplate> <asp:TextBox ID="txt_quantity" runat="server" Text='<%#Container.DataItem("q")%>' AutoPostBack="true" OnTextChanged="QuantityChanged"> </asp:TextBox> </ItemTemplate> </Columns> </asp:DataGrid>Protected Sub QuantityChanged(ByVal sender As Object, ByVal e As EventArgs) Dim txt_quantity As TextBox = DirectCast(sender, TextBox) End SubMetalAsp.Net
All-Star
112034 Points
18232 Posts
Moderator
Re: Getting datakeys while textchanged in datagrid.
Feb 28, 2012 05:48 PM|LINK
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Getting datakeys while textchanged in datagrid.
Feb 28, 2012 05:57 PM|LINK
see this:
http://stackoverflow.com/questions/2818203/get-datakey-values-in-gridview-rowcommand
Raj Sedhain
kengkit
Member
120 Points
244 Posts
Re: Getting datakeys while textchanged in datagrid.
Feb 29, 2012 12:37 PM|LINK
Hi sir, thx for your replied. But i not really what do your mean. Mind to desc more detail. Appreciated. TQ
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Getting datakeys while textchanged in datagrid.
Mar 01, 2012 07:52 AM|LINK
Hi,
Try this in the TextChanged event:
Dim tb As TextBox = DirectCast(sender, TextBox)
Dim dgi As DataGridItem = DirectCast(tb.Parent.Parent, DataGridItem)
Dim pid As String = MyDataGrid.DataKeys(dgi.DataSetIndex).ToString()
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
superguppie
All-Star
48225 Points
8679 Posts
Re: Getting datakeys while textchanged in datagrid.
Mar 01, 2012 01:50 PM|LINK
Adding to that: If you replace tb.Parent.Parent by tb.NamingContainer, you have what MetalAsp.Net meant.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.