Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Editcommancolumn in datagrind in asp.net

Reply
Thread Tools

Editcommancolumn in datagrind in asp.net

 
 
Venkat Chellam
Guest
Posts: n/a
 
      11-04-2004
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
 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      11-04-2004
Venkat Chellam wrote:
> 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


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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Reply With Quote
 
 
 
 
Venkat Chellam
Guest
Posts: n/a
 
      11-09-2004
Thanks scott,

It worked for me. Thanks for all your help.

I am stuck with another problem.

My grid has paging enabled to true. When viewing different pages, it
works fine but the editcommand column with update, edit and cancel.
What happens is then if click the edit link from any row on the first
page of the grid, the grid forws becomes editable and everything works
fine. But if i go the next page of the datagrid and then try to edit
any row from that page, row doesn't become editable. Grid has 10
records in each page.

I trapped on EditCommand of the grid , DataGridEventArgs (the paramter
e)
has the item index value as 0 , actually it should be 11 for second
page.

I am trapping the pagechange event and and setting the page index also
properly
and rebinding the grid with its datasource.

Can you help me

venky




"Scott Mitchell [MVP]" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Venkat Chellam wrote:
> > 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

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

 
Reply With Quote
 
venkat chellam
Guest
Posts: n/a
 
      11-09-2004


Scott, i mean not the column index i mean row index is coming 0 when i
select the 11 record from second page. Its index should be 10(being zero
based.


Following is the code. For the second page i am expecting this value as
10, 11 but i get 0,1 and so an as such its from the first grid page.

private void myDataGrid_EditCommand_1(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int k = e.Item.ItemIndex


}



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist in datagrind - selected index problem wolfgang wagner ASP .Net 4 02-22-2005 07:18 AM
Editcommancolumn in datagrind in asp.net Venkat Chellam ASP .Net 2 11-05-2004 05:41 AM
Editcommancolumn in datagrind in asp.net Venkat Chellam ASP .Net Building Controls 1 11-04-2004 05:02 PM
DataGrind URL Issue with ASP.Net ASP .Net 0 06-28-2003 07:18 PM



Advertisments