Editcommancolumn in datagrind in asp.net

  • Thread starter Thread starter Venkat Chellam
  • Start date Start date
V

Venkat Chellam

I have a question.

I have datagrid in asp.net page. grid will be loaded some information
on page load. One column of the grid is editcommandcolumn type with
edit, update and cancel options.

I don't want the edit button(linktype) to be enabled for all the rows.
Bases on some information, edit link should be enabled or disabled.
Which is the best event to handled and any code snippets will help

thank
venky
 
Venkat, I answered this question in the
microsoft.public.framework.aspnet.datagrid newsgroup. If you are going
to post the same question to multiple newsgroups it is good netiquette
to post to all newsgroups at the same time. This way when replying, my
reply will be applied to all newsgroups.

Anywho, here was my response from the datagrid newsgroup:

======================================================

Venkat, in the ItemDataBound event you can programmatically reference
the Edit button using the following code:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
LinkButton editButton = (LinkButton) e.Item.Cells[index].Controls[0];

// here you can set editButton.Enabled = false if some condition
holds true
}


In the above code the value for index will be the ordinal index of the
EditCommandColumn. If it's the left-most column, index would be 0, if
it's the second left-most column, then 1, and so on.

I use this technique in a number of my own projects. Hope this helps
you out as well. Happy Programming!

======================================================


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
I have a question.

I have datagrid in asp.net page. grid will be loaded some information
on page load. One column of the grid is editcommandcolumn type with
edit, update and cancel options.

I don't want the edit button(linktype) to be enabled for all the rows.
Bases on some information, edit link should be enabled or disabled.
Which is the best event to handled and any code snippets will help

thank
venky

Hi,
In the Item Databound of the datagrid write the following Code
" first check the values for which it should be disabled"
dim lbtn as LinkButton
lbtn=e.item.FindControl("lnkNamEdit")
lbtn.visible=false
 
Back
Top