Editable/Uneditable Gridview rows on condition

M

Mike P

Is it possible to make an editable gridview so that certain rows are
editable and other are not editable, dependent upon a value in one of
the rows columns?
 
W

Winista

You can try handling the click event on client side and verify the
conditions. You can return "false" from that event handler to cancel
postback.
 
P

PeterKellner

Is it possible to make an editable gridview so that certain rows are
editable and other are not editable, dependent upon a value in one of
the rows columns?

I would suggest converting the command to a template so you can access
the link button. Then in your rowcreated event do something like
this.

protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int id = (int) DataBinder.Eval(e.Row.DataItem, "id");
if (id > 1)
{
LinkButton lb = (LinkButton)
e.Row.FindControl("LinkButton1");
lb.Visible = false;
}
}


}
Peter Kellner
http://peterkellner.net
 
P

PeterKellner

Is it possible to make an editable gridview so that certain rows are
editable and other are not editable, dependent upon a value in one of
the rows columns?

Make sure you change the command row to a template first. Then this
code will do the trick:


protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (e.Row.RowIndex == 0)
{
LinkButton lb = (LinkButton)
e.Row.FindControl("LinkButton1");
lb.Text = "newtextbutton";
}
}


}
Peter Kellner
http://peterkellner.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top