Disabling Datagrid Link Button

Discussion in 'ASP .Net Datagrid Control' started by Sharad Nair, Aug 8, 2003.

  1. Sharad Nair

    Sharad Nair Guest

    Hi all,
    I have a datagrid with 3 columns with the last one being a
    link button which does a postback. The page hides/shows a
    panel control with additonal information about the row
    data. But the link button is not applicable to every row
    for certain values no additional info is available and i
    wud like disable the link button, or change the control to
    label. I tried to replace the link control with a label
    control in the DataGrid's ItemDatabound value depending on
    the condition. It works fine, but the problem occurs when
    the link button is clicked. The page post back and all the
    label controls i added disappears.

    ************************************
    here is the sample code.
    If e.Item.ItemType = ListItemType.AlternatingItem Or
    e.Item.ItemType = ListItemType.Item Then
    Dim lnk As LinkButton = CType(e.Item.FindControl
    ("lnkPOD"), LinkButton)
    lnk.CommandArgument = objStock.StockEvent
    If objStock.StockEvent = Stock.EventReceipt Then
    Dim refCell As TableCell = e.Item.Cells(4)
    Dim lbl As New Label
    '- disable the link button and put a label for receipts
    lnk.Visible = False
    lbl.CssClass = "LabelText"
    lbl.Text = objStock.StockAdvice
    lbl.EnableViewState = True
    refCell.Controls.Add(lbl)
    refCell.Text = objStock.StockAdvice
    End If
    End if
    *****************************************

    Does anyone have any idea what could be causing this
    problem.
    Thanks
     
    Sharad Nair, Aug 8, 2003
    #1
    1. Advertising

  2. Sharad Nair

    Jos Guest

    Sharad Nair wrote:
    > Hi all,
    > I have a datagrid with 3 columns with the last one being a
    > link button which does a postback. The page hides/shows a
    > panel control with additonal information about the row
    > data. But the link button is not applicable to every row
    > for certain values no additional info is available and i
    > wud like disable the link button, or change the control to
    > label. I tried to replace the link control with a label
    > control in the DataGrid's ItemDatabound value depending on
    > the condition. It works fine, but the problem occurs when
    > the link button is clicked. The page post back and all the
    > label controls i added disappears.
    >
    > ************************************
    > here is the sample code.
    > If e.Item.ItemType = ListItemType.AlternatingItem Or
    > e.Item.ItemType = ListItemType.Item Then
    > Dim lnk As LinkButton = CType(e.Item.FindControl
    > ("lnkPOD"), LinkButton)
    > lnk.CommandArgument = objStock.StockEvent
    > If objStock.StockEvent = Stock.EventReceipt Then
    > Dim refCell As TableCell = e.Item.Cells(4)
    > Dim lbl As New Label
    > '- disable the link button and put a label for receipts
    > lnk.Visible = False
    > lbl.CssClass = "LabelText"
    > lbl.Text = objStock.StockAdvice
    > lbl.EnableViewState = True
    > refCell.Controls.Add(lbl)
    > refCell.Text = objStock.StockAdvice
    > End If
    > End if
    > *****************************************
    >
    > Does anyone have any idea what could be causing this
    > problem.
    > Thanks


    Controls that are created dynamically need to be re-generated at Page_Load.
    This means that you have to perform databinding for your grid even on
    postback.
    Look here for a general example:
    http://www.codeproject.com/aspnet/RetainingState.asp

    Another idea might be to add both a LinkButton and a Label to
    your grid (in the same column) and make visible the one or
    the other.

    --

    Jos
     
    Jos, Aug 8, 2003
    #2
    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. John Timney \(ASP.NET MVP\)

    Re: disabling link button on a datagrid in .Net

    John Timney \(ASP.NET MVP\), Mar 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    523
    John Timney \(ASP.NET MVP\)
    Mar 7, 2005
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    904
    Kevin Spencer
    May 17, 2005
  3. =?Utf-8?B?cHJhZGVlcF9UUA==?=

    Disabling Link Button Column in Datagrid

    =?Utf-8?B?cHJhZGVlcF9UUA==?=, Nov 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,352
    =?Utf-8?B?cHJhZGVlcF9UUA==?=
    Nov 25, 2005
  4. Kavi

    disabling a a href link

    Kavi, Feb 14, 2007, in forum: HTML
    Replies:
    1
    Views:
    5,539
    Jonathan N. Little
    Feb 15, 2007
  5. Replies:
    2
    Views:
    794
    Jonathan N. Little
    May 15, 2008
Loading...

Share This Page