主頁(yè) > 知識(shí)庫(kù) > gridview實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法分享

gridview實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法分享

熱門(mén)標(biāo)簽:廣州銷(xiāo)售外呼系統(tǒng)定制 云狐人工智能電話機(jī)器人 400電話辦理信任翰諾科技 電銷(xiāo)機(jī)器人 數(shù)據(jù) 怎樣給陜西地圖標(biāo)注顏色 地圖標(biāo)注多少錢(qián)一張 福州人工智能電銷(xiāo)機(jī)器人加盟 宿遷智能外呼系統(tǒng)排名 ai電銷(xiāo)機(jī)器人對(duì)貸款有幫助嗎

復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true"%>

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

script runat="server">
  // 計(jì)算數(shù)據(jù),完全可以從數(shù)據(jù)看取得
  ICollection CreateDataSource()
  {
    System.Data.DataTable dt =new System.Data.DataTable();
    System.Data.DataRow dr;
    dt.Columns.Add(new System.Data.DataColumn("序號(hào)", typeof(System.String)));
    dt.Columns.Add(new System.Data.DataColumn("學(xué)生姓名", typeof(System.String)));
    dt.Columns.Add(new System.Data.DataColumn("語(yǔ)文", typeof(System.Decimal)));
    dt.Columns.Add(new System.Data.DataColumn("數(shù)學(xué)", typeof(System.Decimal)));
    dt.Columns.Add(new System.Data.DataColumn("英語(yǔ)", typeof(System.Decimal)));
    dt.Columns.Add(new System.Data.DataColumn("計(jì)算機(jī)", typeof(System.Decimal)));

    for (int i =0; i 8; i++)
    {
      System.Random rd =new System.Random(Environment.TickCount * i); ;
      dr = dt.NewRow();
      dr[0] = i.ToString();
      dr[1] ="【孟子】"+ i.ToString();
      dr[2] = System.Math.Round(rd.NextDouble() *100, 2);
      dr[3] = System.Math.Round(rd.NextDouble() *100, 2);
      dr[4] = System.Math.Round(rd.NextDouble() *100, 2);
      dr[5] = System.Math.Round(rd.NextDouble() *100, 2);
      dt.Rows.Add(dr);
    }
    System.Data.DataView dv =new System.Data.DataView(dt);
    return dv;
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
    {

      GridView2.DataSource = GridView1.DataSource = CreateDataSource();
      GridView2.DataBind();
      GridView1.DataBind();
    }
  }

  protected void Button1_Click(object sender, EventArgs e)
  {
    Ret1.Text ="";
    foreach (GridViewRow gvr in GridView1.Rows)
    {
      CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
      if (ch.Checked)
      {
        Ret1.Text +="li>GridView1 您選擇的是(鍵值):"+ GridView1.DataKeys[gvr.DataItemIndex].Value.ToString();
      }
    }
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
    Ret2.Text ="";
    foreach (GridViewRow gvr in GridView2.Rows)
    {
      CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
      if (ch.Checked)
      {
        Ret2.Text +="li>GridView2 您選擇的是(鍵值):"+ GridView2.DataKeys[gvr.DataItemIndex].Value.ToString();
      }
    }
  }

  protected void CheckAll(object sender, EventArgs e)
  {
    CheckBox cbx = (CheckBox)sender;
    foreach (GridViewRow gvr in GridView1.Rows)
    {
      CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
      ch.Checked = cbx.Checked;
    }
  }
/script>

html xmlns="http://www.w3.org/1999/xhtml">
head>
  title>GridView 實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法/title>

  script type="text/javascript">
  //![CDATA[
  function CheckAll(oCheckbox)
  {
   var GridView2 = document.getElementById("%=GridView2.ClientID %>");
   for(i =1;i GridView2.rows.length; i++)
   {
    GridView2.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
   }
  }

  //]]>
  /script>

/head>
body>
  form id="Form1" runat="server">
    table style="width:800px;font-size:12px;">
      tr valign="top">
        td>
          asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
            GridLines="Both" CellPadding="4" DataKeyNames="序號(hào)" AutoGenerateColumns="false">
            HeaderStyle BackColor="#EDEDED" Height="26px"/>
            Columns>
              asp:TemplateField>
                HeaderTemplate>
                  asp:CheckBox ID="CheckBox1" runat="server" Text="全選" AutoPostBack="true" OnCheckedChanged="CheckAll"/>
                /HeaderTemplate>
                ItemTemplate>
                  asp:CheckBox ID="ItemCheckBox" runat="server"/>
                /ItemTemplate>
              /asp:TemplateField>
              asp:BoundField DataField="學(xué)生姓名" HeaderText="學(xué)生姓名"/>
              asp:BoundField DataField="語(yǔ)文" HeaderText="語(yǔ)文"/>
              asp:BoundField DataField="數(shù)學(xué)" HeaderText="數(shù)學(xué)"/>
              asp:BoundField DataField="英語(yǔ)" HeaderText="英語(yǔ)"/>
              asp:BoundField DataField="計(jì)算機(jī)" HeaderText="計(jì)算機(jī)"/>
            /Columns>
          /asp:GridView>
          asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="得到選擇的行值"/>
        /td>
        td align="right">
          asp:GridView ID="GridView2" runat="server" Font-Size="12px" BackColor="#FFFFFF"
            GridLines="Both" CellPadding="4" DataKeyNames="序號(hào)" AutoGenerateColumns="false">
            HeaderStyle BackColor="#EDEDED" Height="26px"/>
            Columns>
              asp:TemplateField>
                HeaderTemplate>
                  input id="Checkbox2" type="checkbox" onclick="CheckAll(this)" runat="server"/>label>全選/label>
                /HeaderTemplate>
                ItemTemplate>
                  asp:CheckBox ID="ItemCheckBox" runat="server"/>
                /ItemTemplate>
              /asp:TemplateField>
              asp:BoundField DataField="學(xué)生姓名" HeaderText="學(xué)生姓名"/>
              asp:BoundField DataField="語(yǔ)文" HeaderText="語(yǔ)文"/>
              asp:BoundField DataField="數(shù)學(xué)" HeaderText="數(shù)學(xué)"/>
              asp:BoundField DataField="英語(yǔ)" HeaderText="英語(yǔ)"/>
              asp:BoundField DataField="計(jì)算機(jī)" HeaderText="計(jì)算機(jī)"/>
            /Columns>
          /asp:GridView>
          asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="得到選擇的行值"/>
        /td>
      /tr>
      tr valign="top">
        td>
          asp:Literal ID="Ret1" runat="server">/asp:Literal>
        /td>
        td align="right">
          asp:Literal ID="Ret2" runat="server">/asp:Literal>
        /td>
      /tr>
    /table>
  /form>
/body>
/html>

您可能感興趣的文章:
  • GridView中點(diǎn)擊CheckBox選中一行來(lái)改變此行的顏色
  • gridview 行選添加顏色和事件
  • GridView選擇性導(dǎo)出Excel解決方案
  • 如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel
  • asp.net讀取excel中的數(shù)據(jù)并綁定在gridview
  • GridView生成的HTML代碼示例對(duì)比
  • gridview的buttonfield獲取該行的索引值(實(shí)例講解)
  • Gridview自動(dòng)排序功能的實(shí)現(xiàn)
  • 獲取Gridview中ButtonField的text屬性
  • DevExpress實(shí)現(xiàn)GridView當(dāng)無(wú)數(shù)據(jù)行時(shí)提示消息

標(biāo)簽:宜春 大興安嶺 延安 焦作 新疆 綿陽(yáng) 曲靖 黃南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《gridview實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法分享》,本文關(guān)鍵詞  gridview,實(shí)現(xiàn),服務(wù)器,端,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《gridview實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法分享》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于gridview實(shí)現(xiàn)服務(wù)器端和客戶(hù)端全選的兩種方法分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章