Click here to Skip to main content
14,269,699 members
Rate this:
Please Sign up or sign in to vote.
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: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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,
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


Respone.Redirect("Edit.aspx);
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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;
  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

textbox1.text=Convert.ToString(session["value1"]);
...
...
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100