ASP.NET中通過GRIDVIEW選擇按鈕將資料顯示到TEXTBOX中

來源:互聯網
上載者:User

HTML代碼:

<asp:GridView   ID="GridView1" runat="server" DataKeyNames="ckdh" Height="183px" Style="left: 0px; position: relative;           top: -18px; font-size: small;" Width="864px" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"            AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None"  OnSelectedIndexChanging="GridView1_SelectedIndexChanging" EmptyDataText="未錄入">           <PagerStyle HorizontalAlign="Right" BackColor="#FFCC66" ForeColor="#333333" />           <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="第一頁" PreviousPageText="上一頁" NextPageText="下一頁" LastPageText="最後一頁"  />           <Columns>               <asp:BoundField  DataField="ckdh" HeaderText="出庫單號" SortExpression="ckdh"  />               <asp:BoundField  DataField="ckkb" HeaderText="出庫庫別" SortExpression="ckkb"  />               <asp:BoundField  DataField="ypqx" HeaderText="藥品去向" SortExpression="ypqx"  />               <asp:BoundField  DataField="ypbh" HeaderText="藥品編號" SortExpression="ypbh"  />               <asp:BoundField  DataField="ypmc" HeaderText="藥品名稱" SortExpression="ypmc"  />               <asp:BoundField  DataField="gg" HeaderText="藥品規格" SortExpression="gg"  />               <asp:BoundField  DataField="dw" HeaderText="藥品單位" SortExpression="dw"  />               <asp:BoundField  DataField="sj" HeaderText="出庫價格" SortExpression="sj"  />               <asp:BoundField  DataField="sl" HeaderText="出庫數量" SortExpression="sl"  />           </Columns>           <SelectedRowStyle ForeColor="Navy" BackColor="#FFCC66" Font-Bold="True"  />           <RowStyle ForeColor="#333333" BackColor="#FFFBD6"  />           <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White"  />           <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"  />           <AlternatingRowStyle BackColor="White"  />       </asp:GridView>

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

C#後台代碼:

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs a)    {        TextBox1.Text = GridView1.Rows[a.NewSelectedIndex].Cells[1].Text.ToString();        TextBox2.Text = GridView1.Rows[a.NewSelectedIndex].Cells[2].Text.ToString();        TextBox3.Text = GridView1.Rows[a.NewSelectedIndex].Cells[3].Text.ToString();        TextBox4.Text = GridView1.Rows[a.NewSelectedIndex].Cells[4].Text.ToString();        TextBox5.Text = GridView1.Rows[a.NewSelectedIndex].Cells[5].Text.ToString();        TextBox6.Text = GridView1.Rows[a.NewSelectedIndex].Cells[6].Text.ToString();        TextBox7.Text = GridView1.Rows[a.NewSelectedIndex].Cells[7].Text.ToString();        TextBox8.Text = GridView1.Rows[a.NewSelectedIndex].Cells[8].Text.ToString();        TextBox9.Text = GridView1.Rows[a.NewSelectedIndex].Cells[9].Text.ToString();        Session["shuliang"] = Convert.ToInt32( TextBox9.Text);        //TextBox10.Text = GridView1.Rows[e.NewSelectedIndex].Cells[10].Text.ToString();        //TextBox11.Text = GridView1.Rows[e.NewSelectedIndex].Cells[11].Text.ToString();        // TextBox1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text.ToString();        //Response.Write("<h1>" + sl + "</h1>");            //bh = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text.ToString(); //得到選中行第二個儲存格的文本        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.