当前位置: 移动技术网 > IT编程>开发语言>c# > c#获取gridview的值代码分享

c#获取gridview的值代码分享

2019年07月18日  | 移动技术网IT编程  | 我要评论
gridview设置如下: 复制代码 代码如下:<asp:gridview id="gridviewlb" runat="server" autogeneratec

gridview设置如下:

复制代码 代码如下:

<asp:gridview id="gridviewlb" runat="server" autogeneratecolumns="false" cssclass="tabblue" showcelltooltip=" true"
                emptydatatext="暂时没有记录!" width="100%"  height="100%" allowpaging="true" onpageindexchanging="gridviewlb_pageindexchanging"
                datakeynames="id" pagesize="26" onrowcreated="gridviewlb_rowcreated" onrowdatabound="gridviewlb_rowdatabound"
                allowsorting="true">

              <columns  >
                    <asp:boundfield datafield="id" headertext="编号"  />
                    <asp:boundfield datafield="type" headertext="类型" />
                    <asp:boundfield datafield="item" headertext="项目" ></asp:boundfield>
                    <asp:boundfield datafield="detail" headertext="内容" >
                          <itemstyle width="100px" />
                          <itemstyle width="120px" />
                    </asp:boundfield>
                    <asp:boundfield datafield="basescore" headertext="基本分" />
                    <asp:boundfield datafield="stdevaluation" headertext="评分标准" />
                    <asp:templatefield headertext="打分" >
                          <itemtemplate>
                                <asp:textbox  id="textbox1" runat="server" text="" width="80%" height="24px"></asp:textbox> 
                          </itemtemplate>
                        <itemstyle width="50px" />
                    </asp:templatefield>                  
              </columns>
</asp:gridview>

获得gridview中textbox的值:

显然这里是模板列,可以利用:

复制代码 代码如下:

string str = ((textbox)(this.gridview1.rows[行号].cells[6].findcontrol("textbox1"))).text.trim();

如果不是模板列,可以利用

复制代码 代码如下:

string str = this.gridview1.rows[行号].cells[6].text.trim();

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网