Is there a Namespace Reference somewhere?

  • Thread starter Thread starter jm
  • Start date Start date
J

jm

For example, I cannot get this to work (in my page_load on the
server):

chkCompleted.attributes.add("onclick", "javascript:return confirm('Are
you sure?');")

My code is:

<asp:datagrid....>
<columns>
some boundcolumns
<asp:Template ColumnHeaderText="Completed"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:checkbox id="chkCompleted" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

I get an error that chkCompleted is not declared. My guess is that I
have not imported the correct namespace. I have tried several, just
guessing but I haven't found the right one.

Where is a good reference for this? Thank you and links are
appreciated.
 
Hi,

In fact , the WebControls in DataGrid Template Column appear another control
ID in client html.For example, if you put a "LinkButton1" in the Template
Column, in client side, the ID is auto changed to
"DataGrid1__ctl?_LinkButton1", so that you can't add attributes on ID
"LinkButton1" correctly.

Try to do this: during the event of DataGrid1_ItemDataBound, using
FindControl and add attributes dynamically.

Code:

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.LinkButton lLnkBtn_TargetButton;

if(e.Item.ItemType!=ListItemType.Header&&e.Item.ItemType!=ListItemType.Foote
r)
{
lLnkBtn_TargetButton =
(System.Web.UI.WebControls.LinkButton)e.Item.Cells[2].FindControl("LinkButto
n1");
lLnkBtn_TargetButton.Attributes.Add("onclick","return confirm(\"Are u
sure?\")");
}
}

Kosic
 
Back
Top