Disabling Datagrid Link Button

S

Sharad Nair

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
 
J

Jos

Sharad said:
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.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top