Gridview Basics
Thursday, December 30th, 2010If you’re new to Gridviews this should be a helpful article.
Situation:
You have a limited amount of space horizontally to display your gridview, but someone (boss, client, etc.) has indicated that their is additional information they need to see. Instead of forcing all of the data into a small space and creating a multi-lined field, which is unappealing…add a button that will display the additional info somewhere else on the page, within a model dialog window or message box.
Solution:
The Button control has the following properties; CommandName and CommandArgument. They can be used in the following way:
<asp:Button id=”action” runat=”server” text=’text’ CommandName=”ShowInfo” CommandArgument=’<%#Eval(”ID”) %>’ />
The code behind file will have the following subroutine:
Protected Sub GRIDVIEW_NAME_RowCommand(ByVal sender As Object, ByVal e As CommandEventArgs) Handles GRIDVIEW_NAME.RowCommand
Response.Write(”TEST = ” & e.CommandName)
Response.Write(”TEST = ” & e.CommandArgument)
End Sub
Description:
The system will fire the subroutine and will pass the CommandName and CommandArgument values as parameters. You can have several buttons with several different CommandNames, which will allow you to expand the functionality.
