Click here to Skip to main content
15,916,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm using a grid view with both radiobuttion and text box to answer some questions with comments

aspx page for that control is

XML
<asp:GridView ID="gvOccupancy" runat="server"  AutoGenerateColumns="False" CssClass="gridView"      DataKeyNames="Qid" Width="100%">
                        <Columns>
                           <asp:boundfield datafield="QNo" headerText="#"/>
                            <asp:boundfield datafield="question" />
                            <asp:boundfield datafield="risk_rating" HeaderText="Level" ItemStyle-HorizontalAlign="center" Visible="false"/>
                            <asp:TemplateField headertext="Answer">
                                <ItemTemplate>
                                    <asp:RadioButtonList runat="server" id="rb1Answer" RepeatDirection="Horizontal" RepeatLayout="Flow">
                                        <asp:listitem Text="Yes" value="Yes" />
                                        <asp:listitem Text="No" value="No" />
                                        <asp:listitem Text="N/A" value="N/A" />
                                    </asp:RadioButtonList><br />
                                    <asp:textbox id="txtComments" runat="server" textmode="multiline" height="40" width="600" OnKeyPress="max_Length(event, this, 200)" />
                                    <asp:radiobuttonlist id="rblOptions" runat="server" RepeatLayout="Flow" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>



after answering the questions, the options that i selected along with my comments must be displayed in the grid.

but now the question column only getting filled. But data saved properly and retrieved.

code behind...
C#
string sql = " select b.Descritpion category, id Qid,ROW_NUMBER()        OVER (ORDER BY id) AS  QNo,  A.Question,C.risk_rating,C.answer,C.comment " +                      " from  AppraisalQuestions A inner Join Questioncategory B On A.Question_Number =b.Categorycode and a.Form='AU'and   isActive = 1  and " + category +
                      " left outer join appraisalanswers c     on a.id= c.question_id  and audit_id  = @id    order by id";

          bindGridView(sql, gvName, _params);


C#
protected virtual void bindGridView(string sql, GridView gv, List<SqlParameter> pars = null, String db = "SSS", CommandType type = CommandType.Text)
  {
      if (gv.AllowPaging)
      {
          gv.DataSource = DAL.executeDataTable(sql, pars, type, db);
          gv.DataBind();
      }
      else
      {
          gv.DataSource = type == CommandType.Text ? DAL.executeQuery(sql, pars, db) : DAL.executeStoredProcedureQuery(sql, pars, db);
          gv.DataBind();
      }
  }



please correct me...
Posted
Updated 9-Aug-13 1:56am
v2

1 solution

You're not currently seeing any value because you're not populating the controls--nothing about DataBind is doing that for you automatically. Have a look at the RowDataBound event of your grid. Handle that event, and as each row is being bound, you'll be able to walk its cells and populate the values as you like. Try something like:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    ((TextBox)e.Row.Cells[3].FindControl("txtComments")).Text = "your value here";
}
 
Share this answer
 
Comments
Member 10112611 12-Aug-13 1:17am    
@woopsydoozy :Thanks you very much for your advice..I am new to grid control.

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