C#如何在事件中獲得GridView里面TextBox的值


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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM