<asp:GridView ID="GridViewWebsiteList" SkinId="Skin1" runat="server" AutoGenerateColumns="False" DataKeyNames="WebsiteID" HeaderStyle-ForeColor="White" ShowFooter="True" OnRowCommand="GridViewWebsiteList_RowCommand" OnRowDeleting="GridViewWebsiteList_RowDeleting" OnRowEditing="GridViewWebsiteList_RowEditing" OnRowUpdating="GridViewWebsiteList_RowUpdating" OnRowCancelingEdit="GridViewWebsiteList_RowCancelingEdit" onrowdeleted="GridViewWebsiteList_RowDeleted"> <Columns> <asp:TemplateField> <FooterTemplate> <asp:LinkButton ID="btnNew" runat="server"CommandName="New" Text="New" /> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Website ID" Visible="false"> <EditItemTemplate> <asp:TextBox ID="txtWebsiteID" runat="server" Visible="false"Text='<%# Bind("WebsiteID") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblWebsiteID" runat="server" Visible="false" Text='<%# Bind("WebsiteID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Website Name"> <EditItemTemplate> <asp:TextBox ID="txtWebsiteName" runat="server"Text='<%# Bind("WebsiteName") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblWebsiteName" runat="server" Text='<%# Bind("WebsiteName") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="txtWebsiteName" runat="server"> </asp:TextBox> </FooterTemplate> </asp:TemplateField> </EditItemTemplate>
protected void GridViewWebsiteList_RowUpdating(object sender, GridViewUpdateEventArgs e) {
string theWebsiteID = GridViewWebsiteList.DataKeys[e.RowIndex].Values[0].ToString();
TextBox txtWebsiteName = (TextBox)GridViewWebsiteList.Rows[e.RowIndex].FindControl("txtWebsiteName"); TextBox txtWebsiteURL = (TextBox)GridViewWebsiteList.Rows[e.RowIndex].FindControl("txtWebsiteURL"); TextBox txtServerIP = (TextBox)GridViewWebsiteList.Rows[e.RowIndex].FindControl("txtServerIP");
Update(theWebsiteID, txtWebsiteName.Text, txtWebsiteURL.Text, txtServerIP.Text);
lblMsg.Text = "Updated record for " + txtWebsiteName.Text;
GridViewWebsiteList.EditIndex = -1;
BindGrid(); }