Click here to Skip to main content
15,793,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two pages one is main.aspx and other is editpage.aspx.main.aspx has gridview that has one edit image button in template field.editpage.aspx has some textboxes.i want that when i click on edit image button then page will redirect to editpage.aspx and all the values for that particular row come in the textbox.
please give me solution.i have search on net but i got only for hyperlink field not for template field that has image button.
the gridview is as:
<asp:GridView ID="grdpages" runat="server" AutoGenerateColumns="False" GridLines="Horizontal"
                        Width="715px" ShowFooter="True" DataKeyNames="pageid" 
                        OnRowEditing="grdpages_RowEditing" onrowcommand="grdpages_RowCommand">
                            <asp:BoundField DataField="pagename" HeaderText="Name" />
                            <asp:TemplateField HeaderText="Home">
                                    <asp:RadioButton ID="rdbtnhome" runat="server" />
                                    <asp:Button ID="btnhomepage" runat="server" CssClass="button" PostBackUrl="~/main.aspx"
                                        Text="Home Page" />
                            <asp:TemplateField HeaderText="Edit">
                                    <asp:ImageButton ID="imgbtnedit" runat="server" ImageUrl="~/images/edit copy.png"
                                        CommandName="EditPage" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" />
                            <asp:TemplateField HeaderText="Delete">
                                    <asp:CheckBox ID="chlboxdelete" runat="server" />
                                    <asp:Button ID="btndelete" runat="server" Text="Delete" CssClass="button" 
                                        onclick="btndelete_Click" />
                                    <asp:HiddenField ID="hdnfieldid" runat="server" Value='<%# Eval("pageid") %>' />
Updated 18-Aug-11 0:22am

Use GridView RowCommand event,

In that event you can try this

if(e.CommandName== "EditPage")
//here you can make session eg Session["id"]=e.CommandArgument

//or can pass CommandArgument to QueryString

//and based on it retrieve data on textboxes on edit.aspx

Share this answer
in the event
protected void btndelete_Click(object sender, EventArgs e)
   Button btn = (Button)sender;
   GridViewRow row = (GridViewRow)btn.NamingContainer;
 //do with your selected row what you want
Share this answer
On button click save all the values of particular rows in session variables
and on page load of second page fill the disered textboxes with these session variables. like

protected void imgbtnedit_Click(object sender, EventArgs e)
  GridViewRow Row=((Button)sender).Parent.Parent as GridViewRow;
  int index=Row.RowIndex;

and on page load of editpage.aspx

Share this answer
SURBHI TYAGI 18-Aug-11 6:58am    
at ValueOfColumns i use column name of table that i have create in sqlserver?

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