Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am having a gridview1 in that i am taking four fields

XML
<asp:GridView ID="gridviewFeeDetailsForAnnualy" runat="server" AutoGenerateColumns="False"
                                        BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
                                        CellPadding="3" CellSpacing="1" GridLines="None" Width="783px">
                                        <RowStyle BackColor="#DEDFDE" ForeColor="Black" HorizontalAlign="Center" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="Student ID" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblStudent_ID" runat="server" Text='<%#Eval("Student_ID")%>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Fee Type">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblFee_Type" runat="server" Text='<%#Eval("Fee_Type")%>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Fee Amount">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblFee_Amount" runat="server" Text='<%#Eval("amount")%>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Paid_Amount">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblPaid_Amount" runat="server" Text='<%#Eval("Paid_Amount")%>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Amount To Pay">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblAmount_To_Pay" runat="server" Text='<%#Eval("total_amount")%>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Amount">
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtAmount" runat="server" Width="60px"></asp:TextBox>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:ButtonField CommandName="ViewDetails" HeaderText="Payment Details" Text="View Details" />
                                            <%--<asp:CommandField ShowEditButton="true" HeaderText="Edit" ShowCancelButton="false"/>--%>
                                        </Columns>
                                        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                                        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                        <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                                        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
                                    </asp:GridView>



after entering the values in text box of each row i will click save button then i want to read all the values on the gridview1 then i can insert the records into database one by one.that was my problem.like below i am trying but value is not getting

protected void btnPayFee_Click(object sender, EventArgs e)
{
for (int i = 0; i < gridviewCandidateDetails.Rows.Count; i++)
{
Label Fee_type = (Label)gridviewCandidateDetails.Rows[i].FindControl("lblFee_Type");
TextBox txtamount = (TextBox)gridviewCandidateDetails.Rows[i].FindControl("txtAmount");
}
}
Posted
Updated 10-Mar-13 21:02pm
v2

i think you are binding GridView at Page_Load event outside of IsPostBack put you binding code in IsPostBack check it'll work.
 
Share this answer
 
Comments
ntitish 11-Mar-13 3:44am    
//bellow code i am executing sir but it is not reading textbox value but it is reading label values sir like fee_type what may be the problem sir...

protected void btnPayFee_Click(object sender, EventArgs e)
{
for (int i = 0; i < gridviewCandidateDetails.Rows.Count; i++)
{
Label Fee_type = (Label)gridviewCandidateDetails.Rows[i].FindControl("lblFee_Type");
TextBox txtamount = (TextBox)gridviewCandidateDetails.Rows[i].FindControl("txtAmount");
}
}
Asim Mahmood 11-Mar-13 4:25am    
you are getting lable value because you are binding lable value from DB but in textbox you putting text at runtime that's why you are getting label value.
at which event you are binding Gridview let show me Page_Load code?
protected void btnPayFee_Click(object sender, EventArgs e) { for (int i = 0; i < gridviewCandidateDetails.Rows.Count; i++) { Label Fee_type = (Label)gridviewCandidateDetails.Rows[i].FindControl("lblFee_Type"); TextBox txtamount = (TextBox)gridviewCandidateDetails.Rows[i].FindControl("txtAmount"); } }
 
Share this answer
 

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