G
George
All,
I have a data grid that uses template controls to support editing
data, a footer template to support adding new data, and a delete
button to delete a row. I store the unique id for the row from the
database in a hidden column and I need to use this value if the user
updates or deletes the row. (The HTML code from VS is below.. )
The problem is that after I click the edit button, enter edit
mode, then click the update button, I cannot find a way to get the
unique id from the hidden field in that row so I can do the update.
Any suggestions?
Thanks
George Ceaser
--------------------------------------------------
html
--------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="testgrid1.aspx.vb" Inherits="OurTeamSite.testgrid1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>testgrid1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body style="FONT: 10pt verdana">
<form id="Form1" runat="server">
<h3><font face="Verdana">Using an Edit Command Column in
DataGrid</font></h3>
<asp:datagrid id="MyDataGrid" runat="server" Width="544px"
Font-Names="Verdana" AutoGenerateColumns="False"
OnUpdateCommand="MyDataGrid_Update"
OnCancelCommand="MyDataGrid_Cancel" OnEditCommand="MyDataGrid_Edit"
HeaderStyle-BackColor="#aaaadd" Font-Size="8pt"
Font-Name="Verdana" CellPadding="3" BorderWidth="1px"
BorderColor="Black">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel" EditText="Edit">
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:BoundColumn DataField="TeamName" HeaderText="Team Name">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Password" HeaderText="Password">
<HeaderStyle Width="15%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Division">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Division") %>' ID="lblDivision" >
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList id="ddlDivision" DataSource="<%#
BindDivision() %>" DataTextField="Division"
DataValueField="DivisionID" runat="server">
</aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sponsor">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Sponsor") %>' ID="Label2" NAME="Label2">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Sponsor") %>' ID="Textbox1"
NAME="Textbox1">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False"
DataField="divisionid"></asp:BoundColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
------------------------------
Sub MyDataGrid_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim qtyText As TextBox = CType(e.Item.Cells(5).Controls(0),
TextBox)
End Sub
-----------
NOTE: - The text property of the qtyText control is an empty string
when this executes.
--------------------
I have a data grid that uses template controls to support editing
data, a footer template to support adding new data, and a delete
button to delete a row. I store the unique id for the row from the
database in a hidden column and I need to use this value if the user
updates or deletes the row. (The HTML code from VS is below.. )
The problem is that after I click the edit button, enter edit
mode, then click the update button, I cannot find a way to get the
unique id from the hidden field in that row so I can do the update.
Any suggestions?
Thanks
George Ceaser
--------------------------------------------------
html
--------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="testgrid1.aspx.vb" Inherits="OurTeamSite.testgrid1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>testgrid1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body style="FONT: 10pt verdana">
<form id="Form1" runat="server">
<h3><font face="Verdana">Using an Edit Command Column in
DataGrid</font></h3>
<asp:datagrid id="MyDataGrid" runat="server" Width="544px"
Font-Names="Verdana" AutoGenerateColumns="False"
OnUpdateCommand="MyDataGrid_Update"
OnCancelCommand="MyDataGrid_Cancel" OnEditCommand="MyDataGrid_Edit"
HeaderStyle-BackColor="#aaaadd" Font-Size="8pt"
Font-Name="Verdana" CellPadding="3" BorderWidth="1px"
BorderColor="Black">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel" EditText="Edit">
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:BoundColumn DataField="TeamName" HeaderText="Team Name">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Password" HeaderText="Password">
<HeaderStyle Width="15%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Division">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Division") %>' ID="lblDivision" >
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList id="ddlDivision" DataSource="<%#
BindDivision() %>" DataTextField="Division"
DataValueField="DivisionID" runat="server">
</aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sponsor">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Sponsor") %>' ID="Label2" NAME="Label2">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Sponsor") %>' ID="Textbox1"
NAME="Textbox1">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False"
DataField="divisionid"></asp:BoundColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
------------------------------
Sub MyDataGrid_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim qtyText As TextBox = CType(e.Item.Cells(5).Controls(0),
TextBox)
End Sub
-----------
NOTE: - The text property of the qtyText control is an empty string
when this executes.
--------------------