如何通过选择gridview行来填充文本框 [英] how to fill text box by selecting gridview row

查看:90
本文介绍了如何通过选择gridview行来填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview

I have a gridview

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"AutoGenerateSelectButton="False">


                  <Columns>
                      <asp:BoundField DataField="DesigID" HeaderText="Designation ID">
                          <ItemStyle HorizontalAlign="Center" />
                      </asp:BoundField>
                      <asp:BoundField DataField="DesigName" HeaderText="Designation Name">
                          <ItemStyle HorizontalAlign="Left" />
                      </asp:BoundField>
                               </Columns>
               <selectedrowstyle backcolor="LightCyan" forecolor="DarkBlue" font-bold="true"/>

              </asp:GridView>

和一个文本框

and a textbox

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


我想通过选择gridview行来填充TextBox1.就像当我们单击邮件收件箱中的邮件行然后打开邮件一样.我想在文本框上显示.


I want to fill the TextBox1 by selecting gridview row.Like when we click mail row in mail inbox then mail opens.I want to show on textbox.

推荐答案

//如果您想在文本框中显示指定ID
//in case if you want to show designation id in textbox
protected void grdview_SelectedIndexChanged(object sender, EventArgs e)
   {
TextBox1.Text=grdview.SelectedRow.Cells[0].Text;
   }


//in case if you want to show designation name in textbox
<pre lang="cs">protected void grdview_SelectedIndexChanged(object sender, EventArgs e)
   {
TextBox1.Text=grdview.SelectedRow.Cells[1].Text;
   }</pre>



使其回答并评价它是否满足您的要求.



make it answer and also rate if it satisfies you..


在gridview中添加两个事件
add two event in gridview
onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged1"





protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
      {
         e.Row.Attributes["onmouseover"]="this.style.cursor='hand'";
         e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

         e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select


" + e.Row.RowIndex); } } 受保护的 无效 GridView1_SelectedIndexChanged1(对象发​​件人,EventArgs e) { // con.Open(); AddButton.Text = " ; TextBox1.Text = GridView1.SelectedRow.Cells [ 1 ].Text; 更新= TextBox1.Text; }
" + e.Row.RowIndex); } } protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e) { // con.Open(); AddButton.Text = "Update"; TextBox1.Text = GridView1.SelectedRow.Cells[1].Text; update = TextBox1.Text; }


这篇关于如何通过选择gridview行来填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆