I am using OnRowCommand as my event handler..here is code:
Page code:
<asp:GridView ID="GridViewMUNICIPALITY"
OnRowCommand="GridViewMUNICIPALITY_OnRowCommand"
runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="IDnum"
DataSourceID="SqlDataSourceMUNICIPALITY" ShowFooter="True" CellPadding="5" CellSpacing="5" Font-Bold="True" Font-Size="Large" HorizontalAlign="Right">
<Columns>
<asp:TemplateField ShowHeader="True" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Size="Large" HeaderText="Municipality Items">
<EditItemTemplate>
<asp:LinkButton ID="LinkButtonMUN1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButtonMUN2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButtonInsertMUN" CommandName="Insert" runat="server">Add</asp:LinkButton>
<asp:LinkButton ID="LinkButtonCancelMUN" CommandName="Cancel" runat="server">Cancel</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="IDnum" HeaderText="IDnum" InsertVisible="False" ReadOnly="True" SortExpression="IDnum" />
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBoxMUNINSERT" Text='<%# Bind("Name") %>' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CODE BEHIND:
// MUNICIPALITY LOOKUP TABLE INSERT
protected void GridViewMUNICIPALITY_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert") // this works fine
{
TextBox Name = GridViewMUNICIPALITY.FooterRow.FindControl("TextBoxMUNINSERT") as TextBox;
SqlParameter newMunData = new SqlParameter("@Name", SqlDbType.VarChar, 50);
newMunData.Direction = ParameterDirection.Input;
newMunData.Value = Name.Text;
insertParameters.Add(newMunData);
SqlDataSourceMUNICIPALITY.Insert();
}
if (e.CommandName == "Edit") // MY PROBLEM AREA
{
// Want to grab the value of TextBox1, store it for use in updatecommand as WHERE condition value below
}
if (e.CommandName == "Update") // PENDING SUCCESS IN CONDITION ABOVE ... SHOULD WORK IF ABLE TO STORE VALUE IN ABOVE...RIGHT?
{
TextBox Name = GridViewMUNICIPALITY.FooterRow.FindControl("TextBox1") as TextBox;
SqlDataSource3.UpdateCommand = "UPDATE [PROPERTIES] SET [Municipality] = " + Name.Text + " where [Municipality] = " + Label12.Text;
}
}
Any direction would be appreciated..thanks