Is there a Namespace Reference somewhere?

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.
 
K

Kosic

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
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top