You must Sign In to post a response.
  • Category: ASP.NET

    How to display gridview row values to texbox in button click event

    In run mode as follows

    Coursemajorcode AMC(Dropdownlist) Courseminorcode MC(Dropdownlist) Button(add)

    When i click the add button AMC and MC will be displayed in the gridview.

    In gridview as follows

    Coursemajorcode Courseminorcode
    AMC MC

    I have one textt box as follows

    Pakcagedescription textbox1.

    The courseminorcode from the gridview MC and EFA to be displayed in the textbox1 when i click the add button in gridview.

    for that how can i do in using c#.
  • #762279
    Hello Rao,

    Refer the below code :

    protected void ButtonAdd_Click(object sender, EventArgs e)
    GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
    int index = gvRow.RowIndex;
    TextBox1.Text = GridView1.Rows[index].Cells[1].Text;

    Hope this will work for you.

    One more thing i want to tell you. We are replying and giving solution for each and every thread than why don't you rate us or Choose As Best Answer if it solved your problem.

    You must have to Choose that response as best answer if it helped you. It will motivate us to help you more.

    Same thing we have told you so many times.

    I hope you understand.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762291

    Hello I am also remain if my answer fixed in your issue select as best answer thats helpful to participants and grow our website . when your issue fixed still raise your question if truly means

    I am mention mention lot of time to you you received answer and post another question.

    Your issue not fixed means post again.

    Client Side

    <asp:GridView ID="GrdData1" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="GrdData1_SelectedIndexChanged">
    <asp:BoundField DataField = "EMPID" HeaderText = "EMPID ID" />
    <asp:BoundField DataField = "EMPNAME" HeaderText = "EMPNAME" />

    <asp:TemplateField ItemStyle-Width = "30px" HeaderText = "EMPID">

    Server Side

    protected void GrdData1_SelectedIndexChanged(object sender, EventArgs e)
    int index = GrdData1.SelectedRow.RowIndex;
    string name = GrdData1.SelectedRow.Cells[0].Text;
    TxtName.Text = name;

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762295
    Hi rao,

    As per my understand the post you want to display all "courseminorcode" result into Textbox control right.

    If you are looking the same, the solution is like below

    protected void btnDeleteAttachment_OnClick(object sender, EventArgs e)
    string result=string.Empty;
    foreach(GridViewRow row in gv.Rows)
    result+=row["CourseminorCode"].ToString() + ",";

    If you are expecting something different then please let us know.

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments