Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:GridView ID="gvSections" runat="server" AutoGenerateColumns="false" CssClass="Grid" DataKeyNames="section_id" Width="80%" Style="padding-left: 100px">
<asp:TemplateField ItemStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign="Justify">
<asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_ChildGrid" ImageUrl="~/Images/plusicon.png" CommandArgument="Show" />
<asp:Label ID="lblSectionDis" runat="server" Text='<%# Bind("section_name") %>' Font-Bold="true" Style="font-size: 16px;">
<asp:Panel ID="pnlOrders" runat="server" Visible="false" Style="position: relative">
<asp:GridView ID="gvQuestionAnswer" runat="server" AllowSorting="False" BorderWidth="2px" CellPadding="2" ForeColor="Black" GridLines="None" Width="100%" AutoGenerateColumns="false" OnRowDataBound="gvQuestionAnswer_RowDataBound" AllowPaging="True" OnPageIndexChanging="gvQuestionAnswer_PageIndexChanging" PageSize="5">
<asp:TemplateField HeaderStyle-Width="50" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Center">
<%# Container.DataItemIndex+1 %>
<asp:TemplateField HeaderText="Question No" HeaderStyle-HorizontalAlign="Left" Visible="false">
<asp:Label ID="lblQuestionId" runat="server" Text='<%# Bind("question_id") %>' Width="150">
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<asp:Label ID="lblSectionnew" runat="server" Text='<%# Bind("section_name") %>' Width="700" Visible="false">
<asp:Label ID="lblSectionId" runat="server" Text='<%# Bind("section_id") %>' Visible="false">
<asp:Label ID="lblQuestion" runat="server" Text='<%# Bind("qm_desc") %>'>
<asp:TextBox ID="txtAnswer" runat="server" TextMode="MultiLine" Width="450" Text='<%# Bind("Answer") %>'>
<asp:RequiredFieldValidator ID="RR1" runat="server" ControlToValidate="txtAnswer" Display="None" ValidationGroup="sub" ErrorMessage="Please Enter Answer" ForeColor="Red" SetFocusOnError="true">
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender13" runat="server" Enabled="True" TargetControlID="RR1">
<asp:BoundField ItemStyle-Width="150px" DataField="section_id" HeaderText="Section Id" Visible="false" />
<asp:BoundField ItemStyle-Width="150px" DataField="section_name" HeaderText="Section Name" Visible="false" />

C#
protected void gvQuestionAnswer_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            DataTable dtpageindex = new DataTable();
            dtpageindex = ViewState["SectionQuestions"] as DataTable;
            gvSections.PageIndex = e.NewPageIndex;
            string strSection; string strAnswer; string strQuestionid;
            foreach (GridViewRow row in gvSections.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {

                    GridView gv = row.FindControl("gvQuestionAnswer") as GridView;
                    foreach (GridViewRow gvrow in gv.Rows)
                    {
                        if (gvrow.RowType == DataControlRowType.DataRow)
                        {

                            Label lblQuestionId = gvrow.FindControl("lblQuestionId") as Label;
                            Label lblSectionId = gvrow.FindControl("lblSectionId") as Label;

                            TextBox txtAnswer = gvrow.FindControl("txtAnswer") as TextBox;
                            strAnswer = txtAnswer.Text;
                            strQuestionid = lblQuestionId.Text;

                            foreach (DataRow dr in dtpageindex.Rows)
                            {
                                if (dr["question_id"].ToString() == strQuestionid)
                                {
                                    dr["Answer"] = strAnswer;
                                    dtpageindex.AcceptChanges();
                                }
                            }
                        }
                    }
                    ViewState["SectionQuestions"] = dtpageindex;
                    gv.PageIndex = e.NewPageIndex;
                    gv.DataSource = dtpageindex;
                    gv.DataBind();
                }
            }
        }
        catch (Exception ex)
        {}
    }
Posted
Updated 21-Sep-14 21:31pm
v2

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