Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below shown GridView I haven't got the Updated Value from controls(Ex.TextBox) when I am Adding or Updating Rows.
XML
<asp:GridView ID="grdView" runat="server" ShowFooter="True" Font-Names="Arial"
                     Font-Size="10pt" CellPadding="4" AutoGenerateColumns="false"
                                  CssClass="CSSTableGenerator" Width="100%"
                     OnRowCommand="grdView_rowcommand" OnRowUpdating="grdView_Updating"
                     OnRowEditing="grdView_rowediting"  OnRowCancelingEdit="grdView_RowCanceling"
                     OnRowDeleting="grdView_rowdeleting" >
                   <Columns>

                       <asp:TemplateField HeaderText="Sr.No.">
                       <HeaderTemplate>
                       <asp:Label runat="server" ID="lblSN1" Text="S.N."></asp:Label>
                        </HeaderTemplate>
                           <ItemTemplate>
                           <asp:Label runat="server" ID="lblS" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
                               <asp:Label runat="server" ID="lblSN" Text='<%#Eval("PID") %>' Visible="false" ></asp:Label>
                           </ItemTemplate>
                           <EditItemTemplate>
                             <asp:Label runat="server" ID="lblSAdd" Text='<%#Eval("PID") %>' Visible="false"></asp:Label>
                           </EditItemTemplate>
                           <FooterTemplate>
                           <asp:Label runat="server" ID="lblAdd"></asp:Label>
                           </FooterTemplate>
                       </asp:TemplateField>


                       <asp:TemplateField HeaderText="Pattern Name">
                           <ItemTemplate>
                               <asp:Label ID="lblPattern" runat="server" Text='<%#Eval("Year") %>'></asp:Label>
                           </ItemTemplate>
                           <EditItemTemplate>
                           <asp:TextBox runat="server" ID="txtPName" Text='<%#Eval("Year") %>'></asp:TextBox>
                           </EditItemTemplate>
                            <FooterTemplate>
                           <asp:TextBox runat="server" ID="txtPattermY" ValidationGroup="val1"></asp:TextBox>
                           <asp:RequiredFieldValidator runat="server"  ControlToValidate="txtPattermY" ValidationGroup="val1" ID="rfvtxtBuildingN" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                           </FooterTemplate>
                       </asp:TemplateField>

                       <asp:TemplateField HeaderText="Edit/Delete">
                       <ItemTemplate>
                       <asp:LinkButton runat="server" ID="lbtnEdit" CommandName="Edit" Text="Edit"></asp:LinkButton>
                       <asp:LinkButton runat="server" ID="lbnDelete" Text="Delete" CommandName="Delete"></asp:LinkButton>
                       </ItemTemplate>
                       <EditItemTemplate>
                       <asp:LinkButton runat="server" ID="lbtnUpdate" CommandName="Update" Text="Update"></asp:LinkButton>
                       <asp:LinkButton runat="server" ID="lblCancel" Text="Cencel" CommandName="Cancel"></asp:LinkButton>
                       </EditItemTemplate>
                       <FooterTemplate>
                       <asp:LinkButton runat="server" ID="btnAdd" Text="Add" CommandName="Add" ValidationGroup="val1" CssClass="btn-success" Height="30px" Width="80px"></asp:LinkButton>
                       </FooterTemplate>

                      </asp:TemplateField>


                   </Columns>
                     <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                     <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                 </asp:GridView>



Please Help me out
Posted
Updated 4-Apr-14 22:38pm
v2
Comments
Show you code behind. Also show the Page Load code.

1 solution

Hope so your bind method in pageload is getting problem see the below solution
protected void Page_Load(object sender, EventArgs e)
{
    bind();
    if (!Page.IsPostBack)
    {
        bind();
    }
}

is wrong.

It should be:
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        bind();
    }
}
 
Share this answer
 
v2
Comments
adityatwr007 7-Apr-14 0:01am    
Sir you are n't getting my point.
I mean -
When I want to update with value from txtPatternmY TextBox. It return the previous one value that I want to replace with new value, which I entered in it
[no name] 7-Apr-14 1:15am    
Then you may did it bind problem see again my updated solution.
adityatwr007 8-Apr-14 8:56am    
Yaa right, function was misplaced.

Thanks a lot.
[no name] 8-Apr-14 11:36am    
welcome! so answer was correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900