Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
XML
<form id="form1" runat="server">
    <div>
        <br />

        <asp:Label runat="server" ID="Label14"></asp:Label>

        <br />
        <br />
        <br />
        <br />
    <asp:Label runat="server">First Name :</asp:Label>
        <asp:TextBox runat="server" ID="txtFname"></asp:TextBox><br /><br />
        <asp:Label runat="server">Last Name :</asp:Label>
        <asp:TextBox runat="server" ID="txtLname"></asp:TextBox><br /><br />
        <asp:Label runat="server">Address :</asp:Label>
        <asp:TextBox runat="server" ID="txtAddr"></asp:TextBox><br /><br /><br />

        <asp:Button runat="server" ID="btnsubmit" Text="Submit" OnClick="btnsubmit_Click" />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button runat="server" ID="btnreset" Text="Reset" OnClick="btnreset_Click" />

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnShow" runat="server" OnClick="btnShow_Click" Text="ShowGrid" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    </div>

        <div>


            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                <Columns>
                    <asp:CommandField ShowEditButton="True" />
                   <asp:BoundField DataField="FirstName" HeaderText="First NAme"  />
         <asp:BoundField DataField="LastName" HeaderText="Last NAme "  />
         <asp:BoundField DataField="Address" HeaderText="SAddress" />
         <asp:BoundField DataField="ID" HeaderText="Identity" />


                </Columns>

            </asp:GridView>


        </div>
    </form>



/* when i click on edit in gridview , i want the row values to go to form and can be editable and when clicked on sub,it it should update the gridview */
Posted
Updated 14-Nov-15 0:09am
v2

When you click on the gridview column, open the form and load this rows data in the form.
Then make the form editable.

Try this link[^].
 
Share this answer
 
Comments
syedmaveed 15-Nov-15 23:48pm    
@ Abhinav S, Thank u.. But i dont want to use modal but instead when i click on edit the respective row data should go to form n be placed in particular textbox for editing n updation purpose
XML
           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
           DataKeyNames="FirstName,LastName,Address,ID" OnRowCommand="gv_RowCommand">
               <Columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="FirstName" HeaderText="First NAme"  />
                    <asp:BoundField DataField="LastName" HeaderText="Last NAme "  />
                    <asp:BoundField DataField="Address" HeaderText="SAddress" />
                    <asp:BoundField DataField="ID" HeaderText="Identity" />
                    <asp:ButtonField CommandName="modify" Text="modify" />
               </Columns>
           </asp:GridView>

On your code behind


protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "modify")
       {
           int index = Convert.ToInt32(e.CommandArgument);
           txtFname.Text = gv.DataKeys[index].Values["FirstName"].ToString();
           txtLname.Text = gv.DataKeys[index].Values["LastName"].ToString();
           txtAddr.Text = gv.DataKeys[index].Values["ID"].ToString();
       }
   }
 
Share this answer
 
Thank u guys ... Issue is solved ! :)
 
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