Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
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.NET
<asp:GridView ID="grdpages" runat="server" AutoGenerateColumns="False" GridLines="Horizontal"
                        Width="715px" ShowFooter="True" DataKeyNames="pageid" 
                        OnRowEditing="grdpages_RowEditing" onrowcommand="grdpages_RowCommand">
                        <columns>
                            <asp:BoundField DataField="pagename" HeaderText="Name" />
                            <asp:TemplateField HeaderText="Home">
                                <itemtemplate>
                                    <asp:RadioButton ID="rdbtnhome" runat="server" />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:Button ID="btnhomepage" runat="server" CssClass="button" PostBackUrl="~/main.aspx"
                                        Text="Home Page" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="Edit">
                                <itemtemplate>
                                    <asp:ImageButton ID="imgbtnedit" runat="server" ImageUrl="~/images/edit copy.png"
                                        CommandName="EditPage" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" />
                                </itemtemplate>
                            
                            <asp:TemplateField HeaderText="Delete">
                                <itemtemplate>
                                    <asp:CheckBox ID="chlboxdelete" runat="server" />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:Button ID="btndelete" runat="server" Text="Delete" CssClass="button" 
                                        onclick="btndelete_Click" />
                                </footertemplate>
                            
                            <asp:TemplateField>
                                <itemtemplate>
                                    <asp:HiddenField ID="hdnfieldid" runat="server" Value='<%# Eval("pageid") %>' />
                                </itemtemplate>
                            
                        </columns>
Posted
Updated 17-Aug-11 23:22pm
v3

Hi,
Use GridView RowCommand event,

In that event you can try this

if(e.CommandName== "EditPage")
SQL
//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


Respone.Redirect("Edit.aspx);
 
Share this answer
 
v2
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

C#
protected void imgbtnedit_Click(object sender, EventArgs e)
{
  GridViewRow Row=((Button)sender).Parent.Parent as GridViewRow;
  int index=Row.RowIndex;
  Session["Value1"]=((Label)grdpages.Rows[index].FindControl("ValueOfColumns1")).Text;
Session["Value2"]=((Label)grdpages.Rows[index].FindControl("ValueOfColumns2")).Text;
...
...
...
Response.Redirect("editpage.aspx");
}


and on page load of editpage.aspx

C#
textbox1.text=Convert.ToString(session["value1"]);
...
...
 
Share this answer
 
Comments
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