Take the 2-minute tour ×

I have created a form for saving Medium details, columns are, MID,MediumName,CreationDate,Status.I have bind full table in a gridview name gvmedium, i am having a textbox on the form .I want to fill the text box from grid views value of column MediumName on the template button click event.can any one help me?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You can use CommandName and Command Argument to achieve it and on Code Behind use RowCommand event.

        <asp:LinkButton ID="lnkResetPassword" Text="Reset Password" runat="server" CommandName="ResetPassword" CommandArgument='<%# Bind("UserId") %>'></asp:LinkButton>

and then do your work here

 protected void grdUserGroupList_RowCommand(object sender, GridViewCommandEventArgs e)
            if (e.CommandName == "ResetPassword")
               GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
               int RowIndex = gvr.RowIndex; 
               lblMId.Text = e.CommandArgument.ToString(); 
               txtMedium.Text=gvMedium.Rows[RowIndex ].Cells[0].Text; 
share|improve this answer
I wanted to insert the value in text box on button's which is inside the grid view click event and that grid view is binded to the database table..can u assist me to do that? –  Shaikh Nadeem Apr 4 '13 at 7:34
Can Anyone help me with above problem –  Shaikh Nadeem Apr 4 '13 at 8:49
hi friends i'm waiting for ur help......... –  Shaikh Nadeem Apr 4 '13 at 9:51
I have given you an example with linkbutton click. what's the problem in this? –  Sachin Apr 4 '13 at 9:55
MY CS page is : protected void gvMedium_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "gvbtnUpdate") { lblMId.Visible = true; lblMId.Text = e.CommandArgument.ToString(); int index = Convert.ToInt32(e.CommandArgument); txtMedium.Text=gvMedium.Rows[index].Cells[0].Text; } –  Shaikh Nadeem Apr 4 '13 at 10:10

Your Answer


