Hi Joe,
When you click on an item the row, the datagrid fires an ItemCommand event
and sends along the row details in the event arguments. You can use that
information to get an instance of the datagrid row and from it the contents
of any cell. In the code below, I create an instance of the TableCell object
calling it cellSize. I happen to know that within the grid row, the content
I'm after is in the 2 row (zero-based). Therefore, I can extract the text
and do what I want with it.
I've included the complete source code below for your dining and dancing
pleasure.
Private Sub DataGrid1_ItemCommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.ItemCommand
Dim cellSize As TableCell
cellSize = e.Item.Cells(2)
Label1.Text = cellSize.Text
End Sub
Does this help?
Ken
Public Class dgimgclick
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_ItemCommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.ItemCommand
Dim cellSize As TableCell
cellSize = e.Item.Cells(2)
Label1.Text = cellSize.Text
End Sub
Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("Item_no", GetType(Int32)))
dt.Columns.Add(New DataColumn("Item_name", GetType(String)))
dt.Columns.Add(New DataColumn("Size", GetType(String)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
If i > 7 Then
dr(2) = "L"
ElseIf i < 7 And i > 3 Then
dr(2) = "M"
Else
dr(2) = "S"
End If
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
End Class
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="dgimgclick.aspx.vb" Inherits="p4320work.dgimgclick"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>dgfooter</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp

ataGrid id="DataGrid1" runat="server" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
<asp:ButtonColumn DataTextField="Item_no" HeaderText="Item Number"
CommandName="itemnum"></asp:ButtonColumn>
<asp:BoundColumn DataField="Item_name" ReadOnly="True" HeaderText="Item
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Size" HeaderText="Size"></asp:BoundColumn>
</Columns>
</asp

ataGrid>
</form>
<P> </P>
<P>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
</body>
</HTML>