I have a default page where the user inserts all the values. And to view all the values, it can go to another page which has the gridview. What I want is when they click on the Select of the gridview, its should redirect them to the Default page's EditItemTemplate,
where they can view the details of already inserted data.
use hyperlinkfield for gv datanavigateurl="id" datanavigateurlformat="default.aspx?id={0}" then in page load event default page check request.querystring("id"), if null goto insert mode else go to edit mode that using the passed value.
Programming to simplify, dont look for hard way
Marked as answer by sacah4 on Nov 07, 2012 08:15 PM
sacah4
Member
3 Points
7 Posts
GridView_SelectedIndexedChanged to redirect to EditItemTemplate form.
Nov 02, 2012 09:16 PM|LINK
Hi,
I have a default page where the user inserts all the values. And to view all the values, it can go to another page which has the gridview. What I want is when they click on the Select of the gridview, its should redirect them to the Default page's EditItemTemplate, where they can view the details of already inserted data.
Please any help!
Currently my Gridview.aspx code is
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.color='red'";
e.Row.Attributes["onmouseout"] ="this.style.cursor='none';this.style.textDecoration='none';this.style.color='black';";
e.Row.Attributes.Add("onclick",Page.ClientScript.GetPostBackEventReference((Control)sender,"Select$"
+ e.Row.RowIndex.ToString()));
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
Response.Redirect( "Default.aspx?reqby="+ row.Cells[2].Text);
}
oned_gk
All-Star
31021 Points
6354 Posts
Re: GridView_SelectedIndexedChanged to redirect to EditItemTemplate form.
Nov 02, 2012 11:09 PM|LINK
sarathi125
Star
13599 Points
2691 Posts
Re: GridView_SelectedIndexedChanged to redirect to EditItemTemplate form.
Nov 03, 2012 04:04 PM|LINK
Hi,
GridView.SelectedRow Property
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow.aspx
within SelectedIndexChanged , redirect to another page
or use a Button , set command name ="select", then within GridView1_RowCommand
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.85).aspx
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int selectedIndex = int.Parse(e.CommandArgument.ToString());
string _commandName = e.CommandName;
switch (_commandName)
{
case ("select"):
{
redirect to another page
}
}
}
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
sacah4
Member
3 Points
7 Posts
Re: GridView_SelectedIndexedChanged to redirect to EditItemTemplate form.
Nov 06, 2012 02:30 PM|LINK
I have been trying to do what you said. But it is still opening the InsertItempage
if (!IsPostBack)
{
string sid = Request.QueryString["ReqBy"];
if (sid != null)
{
FormView1.DefaultMode =FormViewMode.Edit;
}
else
{
FormView1.DefaultMode =FormViewMode.Insert;
}
The gridview has this code
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//Redirecting to the user information
GridViewRow
row = GridView1.SelectedRow;
Response.Redirect("OPsExcellence.aspx?reqBy="+ row.Cells[2].Text);
}
***********************************************************************************************************
Update : It works for me. I jst changed the
FormView1.DefaultMode =FormViewMode.Edit;
to
FormView1.ChangeMode =FormViewMode.Edit;
Thank you all for your help.
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: GridView_SelectedIndexedChanged to redirect to EditItemTemplate form.
Nov 07, 2012 09:26 AM|LINK
This works for me:
in current page:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridViewRow row = GridView1.SelectedRow; if(row!=null) Response.Redirect("OPsExcellence.aspx?reqBy=" + row.Cells[2].Text); else Response.Redirect("OPsExcellence.aspx?reqBy="); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.color='red'"; e.Row.Attributes["onmouseout"] = "this.style.cursor='none';this.style.textDecoration='none';this.style.color='black';"; e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference((Control)sender, "Select$"+ e.Row.RowIndex.ToString())); } }in OPsExcellence.aspx page:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sid = Request.QueryString["ReqBy"]; if (string.IsNullOrEmpty(sid)) { EmployeeFormView.DefaultMode = FormViewMode.Insert; } else { EmployeeFormView.DefaultMode = FormViewMode.Edit; } } }Feedback to us
Develop and promote your apps in Windows Store