Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Already the row number " + GridView2.EditIndex + " is in edit mode.')", true);
return;
}
GridView2.EditIndex = e.NewEditIndex;
Fetch();
}
ii) dont register below onclick event on every postback of Render event, instead of just based on some condition register only when the grid is not in edit mode i.e whene ever grid goes in edit mode save some flag in viewstate put if condition to check
the flag before registering onclick event
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Already the row number " + GridView2.EditIndex + " is in edit mode.')", true);
Pravind
Member
64 Points
230 Posts
GridView Validation on row change
May 03, 2012 06:05 AM|LINK
HI,
I am using save and cancel link buttons for each row when the user clicks on a row.
My problem is when the user clicks on one row and immediately clicks on other row,first row is getting disappeared.
Is there any way to set validation that he must click on save or cancel, before he clicks on other row.
Can any1 help me on this?
vsdev
Contributor
2230 Points
453 Posts
Re: GridView Validation on row change
May 03, 2012 06:21 AM|LINK
Please provide some code and markup.
Blog: dotnetthoughts
Download Capture It Plus
Pravind
Member
64 Points
230 Posts
Re: GridView Validation on row change
May 03, 2012 06:52 AM|LINK
Hi ,
Thanks for reply.
The below code is to edit the row when user clicks on that row.Iam enabling save and cancel here.
Problem is,if user clicks on one row and immediately clicks on other row,first row data is getting disappeared.
Is there anyway to put validations that click on save or cancel is mandatory
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
//code to disable save and cancel for all rows except for selected row
foreach (GridViewRow row in GridView2.Rows)
{
if (row.RowType == DataControlRowType.DataRow &&
row.RowState.HasFlag(DataControlRowState.Edit) == false)
{
row.Attributes["onmouseover"] = "this.style.cursor='help';this.style.textDecoration='Bold'this.style.background='#f00';";
row.Attributes["onmouseout"] = "this.style.textDecoration='nonse';";
// enable click on row to enter edit mode
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(GridView2, "Edit$" + row.RowIndex, true);
ImageButton sav = (ImageButton)row.FindControl("Save");
sav.Visible = false;
ImageButton cance = (ImageButton)row.FindControl("Cancel");
cance.Visible = false;
}
}
base.Render(writer);
}
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView2.EditIndex = e.NewEditIndex;
Fetch();
}
karthicks
All-Star
31334 Points
5414 Posts
Re: GridView Validation on row change
May 03, 2012 09:14 AM|LINK
hi, you can solve this issue in two ways:
i) check if grid is already in edit mode dont rebind with new edit index
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
if( GridView2.EditIndex >-1){
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Already the row number " + GridView2.EditIndex + " is in edit mode.')", true);
return;
}
GridView2.EditIndex = e.NewEditIndex;
Fetch();
}
ii) dont register below onclick event on every postback of Render event, instead of just based on some condition register only when the grid is not in edit mode i.e whene ever grid goes in edit mode save some flag in viewstate put if condition to check the flag before registering onclick event
row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(GridView2, "Edit$" + row.RowIndex, true);
if this solution is not solved your problem then post your full code
Karthick S
Pravind
Member
64 Points
230 Posts
Re: GridView Validation on row change
May 03, 2012 09:42 AM|LINK
hi,
thanks for ur reply.U rocks:-)
Pravind
Member
64 Points
230 Posts
Re: GridView Validation on row change
May 03, 2012 10:16 AM|LINK
Hi,
iam still facing the same problem.It is showing the validation message,but still iam able to enter into different row.
My problem is iam not using EDIT command,iam just using row click to enable the user to enter into edit mode.
this is my code.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
//code to disable save and cancel for all rows except for selected row
foreach (GridViewRow row in GridView2.Rows)
{
if (row.RowType == DataControlRowType.DataRow &&
row.RowState.HasFlag(DataControlRowState.Edit) == false)
{
row.Attributes["onmouseover"] = "this.style.cursor='help';this.style.textDecoration='Bold'this.style.background='#f00';";
row.Attributes["onmouseout"] = "this.style.textDecoration='nonse';";
// enable click on row to enter edit mode
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(GridView2, "Edit$" + row.RowIndex, true);
ImageButton sav = (ImageButton)row.FindControl("Save");
sav.Visible = false;
ImageButton cance = (ImageButton)row.FindControl("Cancel");
cance.Visible = false;
}
}
base.Render(writer);
}
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
//Fetch();
if (GridView2.EditIndex > -1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Already the row number " + GridView2.EditIndex + " is in edit mode.')", true);
return;
}
else
{
GridView2.EditIndex = e.NewEditIndex;
Fetch();
}
}
Pravind
Member
64 Points
230 Posts
Re: GridView Validation on row change
May 03, 2012 11:13 AM|LINK
Hi,
Can you help me on this?
Is there any other way to enable edit mode when the user clicks on a row without using EDIT command.
Please help me on this?