Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview
ASP.NET
<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.NET
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

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.
Posted
Updated 11-May-12 2:11am
v6

//in case if you want to show designation id in textbox
C#
protected void grdview_SelectedIndexChanged(object sender, EventArgs e)
   {
TextBox1.Text=grdview.SelectedRow.Cells[0].Text;
   }

XML
//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..
 
Share this answer
 
add two event in gridview
HTML
onrowdatabound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChanged1"


C#
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);
    }
   }

   protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
   {
       // con.Open();
       AddButton.Text = "Update";
       TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
       update = TextBox1.Text;

   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900