2
Answers

Update GridView not retrieving textbox new values

Grant Volker

Grant Volker

14y
5.4k
1

Hi, I'm having trouble retrieving the values from textbox in my aspx page. Please can someone help?
Here's a snippet from the aspx page ...
 

           <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> 

 
and here's the code behind snippet.
It's the txtWebsiteName, txtWebsiteURL, txtServerIP text boxes that my code behind does not retrieve the data from.
 
        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();
        }

Any help would really be appreciated!
Thanks,
Grant
Answers (2)