Hi Alex,
For such scenario, as Steve has mentioned, we may need to use code to
programmatically add the client script for the button. Also, are you using
the built-in button column in DataGrid as below?
<asp:ButtonColumn ButtonType="linkButton" ></asp:ButtonColumn>
If so, it'll be very hard to reference the actual button object at runtime
(so as to custimze it) because the button id is autogenerated and it's
unsafe to locate sub controls through control index. I think you can
consider use template column instead of built-in column for such scenario.
And in VS IDE's designview , it provide the wizard for us to convert a
button column to a template column. For example, the above link button
column can be converted to the below template column:(I add the id for the
link button so that we can referece it later):
=========
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server"
CausesValidation="false" CommandName="" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
==============
Then, in DataGrid's ItemdataBound event, we can use the following code to
locate the linkbutton and add client-sdie script behavior for it:
protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
LinkButton lb = e.Item.FindControl("lbDelete") as LinkButton;
lb.OnClientClick = "if(!confirm('are you sure to delete this
item?')){return false;}";
}
}
Hope this helps. If there is anything I missed, please feel free to post
here.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)