S
Sue
Help! Using nested datagrids in web app using VStudio 2003, IIS, SQLServer.
Got the data to load just find in both the outer and inner datagrids. I need
to capture a "select" button click in the inner datagrid, pull the value of
the button text from the clicked
button, and use the value to call a sub to populate controls further down in
the page. I've tried adding
a handler to the inner datagrid to capture the button click, wired up the
ItemCommand in the web server control
in the html page (e.g. onItemCommand="DG_Employee_ItemCommand(... handles
DG_Employee.ItemCommand), and
tried assigning it in the outer DG_OnItemDataBound sub (see code below)
without success. The page does a
postback, but nothing happens. I've debugged this page to a fare-thee-well
and am ready to throw the
computer out the window. I know I'm missing something simple, but can't
identify it. Anyone have a clue?
HTML snip and code-behind snips below...
tia,
Sue, the frustrated
' snip of html page
<asp:datagrid id="DG" Runat="server" Width="100%">
<Columns>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"
DataTextField="PositionID" Visible="false" />
<asp:BoundColumn DataField="PositionNumber"
SortExpression="PositionNumber" HeaderText="Pos No" />
<asp:BoundColumn DataField="PositionDepartmentDescription"
SortExpression="PositionDepartmentDescription"
HeaderText="Dept" />
<asp:TemplateColumn>
<ItemTemplate>
<asp
ataGrid ID="DG_Employee" Runat="server" Width="100%">
<Columns>
<asp:ButtonColumn ButtonType= "PushButton" CommandName="Select"
DataTextField="EmployeeID" />
<asp:BoundColumn ItemStyle-Width="25%" DataField="Name"
HeaderText="Name" />
<asp:BoundColumn itemstyle-width="25%"
DataField="DepartmentDescription" HeaderText="Dept" />
</Columns>
</asp
ataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
' code behind page
Private Sub DG_ItemDataBound(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DG.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.SelectedItem
Dim button As LinkButton =
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Cells(1).Attributes("onclick") =
Page.GetPostBackClientHyperlink(button, "")
e.Item.Cells(2).Attributes("onclick") =
Page.GetPostBackClientHyperlink(button, "")
e.Item.Attributes.Add("onmouseover",
"javascript:this.style.cursor='hand';")
Dim Details_DG As DataGrid
Details_DG = CType(e.Item.Cells(3).Controls(1), DataGrid)
AddHandler Details_DG.ItemCommand, AddressOf
DG_Employee_ItemCommand
Details_DG.AutoGenerateColumns = False
Dim SQLOps As New SQLOperations
Dim DGE_DS As New DataSet
' this function returns a dataset
DGE_DS = SQLOps.SQLReturnDataSet("select * from detail
where ID=" & someID)
' & " and recordstatus = 'Active' order by Name")
SQLOps = Nothing
Details_DG.DataSource = DGE_DS
Details_DG.DataBind()
end select
end sub
Private Sub DG_ItemCommand(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.ItemCommand
If Not e.CommandName = "Page" Then
If e.CommandName = "Select" Then
Session("ThisPositionID") =
CType(CType(e.Item.Cells(0).Controls(0), System.Web.UI.Control),
LinkButton).Text
Call LoadPositionInfo()
End If
End If
End Sub
Private Sub DG_Employee_ItemCommand(ByVal source As System.Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DG_Employee.ItemCommand
If Not e.CommandName = "Page" Then
If e.CommandName = "Select" Then
Session("ThisEmployeeID") =
CType(CType(e.Item.Cells(0).Controls(0), System.Web.UI.Control),
LinkButton).Text
Call LoadEmployeeInfo()
End If
End If
End Sub
Got the data to load just find in both the outer and inner datagrids. I need
to capture a "select" button click in the inner datagrid, pull the value of
the button text from the clicked
button, and use the value to call a sub to populate controls further down in
the page. I've tried adding
a handler to the inner datagrid to capture the button click, wired up the
ItemCommand in the web server control
in the html page (e.g. onItemCommand="DG_Employee_ItemCommand(... handles
DG_Employee.ItemCommand), and
tried assigning it in the outer DG_OnItemDataBound sub (see code below)
without success. The page does a
postback, but nothing happens. I've debugged this page to a fare-thee-well
and am ready to throw the
computer out the window. I know I'm missing something simple, but can't
identify it. Anyone have a clue?
HTML snip and code-behind snips below...
tia,
Sue, the frustrated
' snip of html page
<asp:datagrid id="DG" Runat="server" Width="100%">
<Columns>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"
DataTextField="PositionID" Visible="false" />
<asp:BoundColumn DataField="PositionNumber"
SortExpression="PositionNumber" HeaderText="Pos No" />
<asp:BoundColumn DataField="PositionDepartmentDescription"
SortExpression="PositionDepartmentDescription"
HeaderText="Dept" />
<asp:TemplateColumn>
<ItemTemplate>
<asp
<Columns>
<asp:ButtonColumn ButtonType= "PushButton" CommandName="Select"
DataTextField="EmployeeID" />
<asp:BoundColumn ItemStyle-Width="25%" DataField="Name"
HeaderText="Name" />
<asp:BoundColumn itemstyle-width="25%"
DataField="DepartmentDescription" HeaderText="Dept" />
</Columns>
</asp
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
' code behind page
Private Sub DG_ItemDataBound(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DG.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.SelectedItem
Dim button As LinkButton =
CType(e.Item.Cells(0).Controls(0), LinkButton)
e.Item.Cells(1).Attributes("onclick") =
Page.GetPostBackClientHyperlink(button, "")
e.Item.Cells(2).Attributes("onclick") =
Page.GetPostBackClientHyperlink(button, "")
e.Item.Attributes.Add("onmouseover",
"javascript:this.style.cursor='hand';")
Dim Details_DG As DataGrid
Details_DG = CType(e.Item.Cells(3).Controls(1), DataGrid)
AddHandler Details_DG.ItemCommand, AddressOf
DG_Employee_ItemCommand
Details_DG.AutoGenerateColumns = False
Dim SQLOps As New SQLOperations
Dim DGE_DS As New DataSet
' this function returns a dataset
DGE_DS = SQLOps.SQLReturnDataSet("select * from detail
where ID=" & someID)
' & " and recordstatus = 'Active' order by Name")
SQLOps = Nothing
Details_DG.DataSource = DGE_DS
Details_DG.DataBind()
end select
end sub
Private Sub DG_ItemCommand(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.ItemCommand
If Not e.CommandName = "Page" Then
If e.CommandName = "Select" Then
Session("ThisPositionID") =
CType(CType(e.Item.Cells(0).Controls(0), System.Web.UI.Control),
LinkButton).Text
Call LoadPositionInfo()
End If
End If
End Sub
Private Sub DG_Employee_ItemCommand(ByVal source As System.Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DG_Employee.ItemCommand
If Not e.CommandName = "Page" Then
If e.CommandName = "Select" Then
Session("ThisEmployeeID") =
CType(CType(e.Item.Cells(0).Controls(0), System.Web.UI.Control),
LinkButton).Text
Call LoadEmployeeInfo()
End If
End If
End Sub