使用radiobutton和textbox绑定gridview [英] bind gridview with radiobutton and textbox

查看:67
本文介绍了使用radiobutton和textbox绑定gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有radiobuttion和文本框的网格视图来回答一些带注释的问题



该控件的aspx页面是



i'm using a grid view with both radiobuttion and text box to answer some questions with comments

aspx page for that control is

<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...

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);







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...

推荐答案

您当前没有看到任何值,因为您没有填充控件 - DataBind没有任何关于您自动执行此操作的信息。看看你的网格的RowDataBound事件。处理该事件,并且当每行被绑定时,您将能够遍历其单元格并根据需要填充值。尝试以下方法:

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:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    ((TextBox)e.Row.Cells[3].FindControl("txtComments")).Text = "your value here";
}


这篇关于使用radiobutton和textbox绑定gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆