Question
I have a gridview with one column called "Advertiser". When the "Edit" button is clicked, the litteral-control shall be replaced with an textbox control, and the "Edit button shall be replaced with "Save" and "Cancel" buttons.
The datagrid is filled correctly with data, but I dont know how to write the "Update" or "Cancel" command.
Here is my code so far:
--------------
ASPX
--------------
<asp:GridView runat="server" id="grdAdvertisers" AutoGenerateColumns="false" ShowHeader="false" OnRowEditing="grdAdvertisers_RowEditing">
<EditRowStyle BackColor="yellow" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Edit" Text="Edit" Width="45px" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton CommandName="Update" Text="Update" Width="45px" runat="server" />
<asp:LinkButton CommandName="Cancel" Text="Cancel" Width="45px" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"AdvertiserName ") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAdvertiser" Text='<%# DataBinder.Eval(Container.DataItem,"AdvertiserName ") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
------------------
ASPX.CS
------------------
private void bindAdvertisers()
{
SqlConnection Conn = new SqlConnection(Variables.ConnString);
SqlCommand cmd = new SqlCommand("usp_AdvertiserNames", Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
this.grdAdvertisers.DataSource = dr;
this.grdAdvertisers.DataBind();
cmd.Connection.Close();
cmd.Dispose();
Conn.Dispose();
}
protected void grdAdvertisers_RowEditing(object sender, GridViewEditEventArgs e)
{
//Response.Write(e.NewEditIndex);
}