Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I am working on a project of School using the Layered pattern..My problem is described below
I make a grid view in grid i make 2 bound field and four text boxes...


<Columns>
<asp:BoundField DataField ="StudentId" HeaderText="ID" ></asp:BoundField>
<asp:BoundField DataField ="name" HeaderText="Name" ></asp:BoundField>



<asp:TemplateField HeaderText="Quizez">
<ItemTemplate>
<asp:TextBox ID="quizez" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assignments">
<ItemTemplate>
<asp:TextBox ID="assignments" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sessional1">
<ItemTemplate>
<asp:TextBox ID="sessional1" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sessional2">
<ItemTemplate>
<asp:TextBox ID="sessional2" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Terminal">
<ItemTemplate>
<asp:TextBox ID="terminal" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:TextBox ID="total" runat="server" Width="50px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>


</Columns>
;
</asp:GridView>



Now i want to store the bound field data which include ID and Name and also text boxes data in a
new table TblResult....Me problem is that how to access bound data and text boxes in code file..
Any Solution
Posted
Comments
Sergey Alexandrovich Kryukov 2-Sep-14 17:15pm    
If the data is bound, work with data source not, UI. Reduce all the work with UI to population of data from data source and updating data source from UI...
—SA

1 solution

Iterate through each Gridview row and find control and if found cast it to proper type.

C#
foreach(GridViewRow row in grdViewName.Rows)
{
        string studentId = row.Cells[0].Text.Trim(); //Databound column
        if(row.FindControl("sessional1")!=null) // Check that textbox exists
        {
           string sessional1= ((TextBox)row.FindControl("sessional1")).Text.Trim(); // Get value
        }  

}
 
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