Editcommancolumn in datagrind in asp.net

Discussion in 'ASP .Net Datagrid Control' started by Venkat Chellam, Nov 4, 2004.

  1. 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 Chellam, Nov 4, 2004
    #1
    1. Advertising

  2. 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.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Nov 4, 2004
    #2
    1. Advertising

  3. 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]" <> wrote in message news:<>...
    > 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!
     
    Venkat Chellam, Nov 9, 2004
    #3
  4. 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!
     
    venkat chellam, Nov 9, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    DataGrind URL Issue with ASP.Net

    Guest, Jun 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    505
    Guest
    Jun 28, 2003
  2. Venkat Chellam

    Editcommancolumn in datagrind in asp.net

    Venkat Chellam, Nov 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    356
    thomson
    Nov 5, 2004
  3. wolfgang wagner
    Replies:
    4
    Views:
    629
    wolfgang wagner
    Feb 22, 2005
  4. Venkat Chellam

    Editcommancolumn in datagrind in asp.net

    Venkat Chellam, Nov 4, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    125
    Scott Mitchell [MVP]
    Nov 4, 2004
  5. Amelyan
    Replies:
    2
    Views:
    178
    Amelyan
    Apr 25, 2005
Loading...

Share This Page