欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#获取gridview的值代码分享

程序员文章站 2024-02-19 19:53:58
gridview设置如下: 复制代码 代码如下:

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