colonialiu20
asked on
ButtonLink in Datagrid passes ID to method
I use VB.NET
I have a datagrid which has been filled. I want to have a column which contains a LinkButton. When pressed that Link Button causes a Panel to appear that allows me to add records.
I know how to cause a Link Button to make the panel appear, disapear, etc.
But I want that Link Button to pass an ID from that datagrid record to that Panel (to a method for use in a database)
I know I can create a Hyperlink button to pass the ID in a URL, but I can't get that to work in this case.
I need an example of one of the following:
1) (Preferred) Link Button in DataGrid passes an ID to a method. Let's say the method just does a response.write of the ID.
2) Hyperlink passes BOTH the ID of a record in addition to an ID already in the URL.
Seems simple but I'm at a loss for the right solution.
Bonus points if both are answered and explained.
I have a datagrid which has been filled. I want to have a column which contains a LinkButton. When pressed that Link Button causes a Panel to appear that allows me to add records.
I know how to cause a Link Button to make the panel appear, disapear, etc.
But I want that Link Button to pass an ID from that datagrid record to that Panel (to a method for use in a database)
I know I can create a Hyperlink button to pass the ID in a URL, but I can't get that to work in this case.
I need an example of one of the following:
1) (Preferred) Link Button in DataGrid passes an ID to a method. Let's say the method just does a response.write of the ID.
2) Hyperlink passes BOTH the ID of a record in addition to an ID already in the URL.
Seems simple but I'm at a loss for the right solution.
Bonus points if both are answered and explained.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You gave me what I needed.
Essentially I was looking for this syntax:
Sub DataGrid (ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgList.ItemCommand
and seeing the command argument could be retrieved with e.CommandArgument assuming e was a 'DataGrid'CommandEventArgs
Within the datagrid 'dgDistrictStudents' I have a column which includes the following:
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="addStudentToSlot" runat="server" CommandArgument='<%# Container.DataItem("StuStu dentID") %>' Text="| Add" />
</ItemTemplate>
</asp:TemplateColumn>
*In Code Behind*
Sub addStudent_Click(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgDistrictStudents.ItemCom mand
Dim intItemID As Integer
intItemID = e.Item.ItemIndex
Response.Write(e.CommandAr gument)
End Sub
Thanks for the help!
Essentially I was looking for this syntax:
Sub DataGrid (ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgList.ItemCommand
and seeing the command argument could be retrieved with e.CommandArgument assuming e was a 'DataGrid'CommandEventArgs
Within the datagrid 'dgDistrictStudents' I have a column which includes the following:
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="addStudentToSlot" runat="server" CommandArgument='<%# Container.DataItem("StuStu
</ItemTemplate>
</asp:TemplateColumn>
*In Code Behind*
Sub addStudent_Click(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgDistrictStudents.ItemCom
Dim intItemID As Integer
intItemID = e.Item.ItemIndex
Response.Write(e.CommandAr
End Sub
Thanks for the help!
intItemIndex = e.Item.ItemIndex + (rptrList.CurrentPageIndex
should just be
intItemIndex = e.Item.ItemIndex
if you aren't doing any sort of paging.