Hi all,
We have DataGrid control in Web Form, our client requires to be able to
click anywhere of a row to fire the event same as LinkBotton column is
clicked. We we did in ASP.NET 1.1 is
in ASPX page
<asp:DataGrid id="MyGrid" runat="server" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" runat="server"
EnableViewState="True">
<Columns>
<asp:ButtonColumn Text="" CommandName="Select" Visible="false" />
<asp:BoundColumn DataField="MyText" SortExpression="" />
</Columns>
<PagerStyle Mode="NumericPages" />
</asp:DataGrid>
in code-behind
private void MyGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem
|| e.Item.ItemType == ListItemType.SelectedItem) {
LinkButton button = (LinkButton)e.Item.Cells[0].Controls[0];
e.Item.Attributes["onclick"] = Page.GetPostBackClientHyperlink(button,
"");
}
}
private void dLeads_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) {
if (e.CommandName == "Select") {
// my logic
}
}
Basically, the idea is to hijack the event of ButtonColum of DataGrid to set
to the <TR>.
After I converted the code to ASP.NET 2.0, I cannot use this logic any more,
because I get "Invalid postback or callback argument. Event validation is
enabled using in configuration or in a page. For security purposes, this
feature verifies that arguments to postback or callback events originate
from the server control that originally rendered them. If the data is valid
and expected, use the ClientScriptManager.RegisterForEventValidation method
in order to register the postback or callback data for validation." error
message, unless I turn EnableEventValidation of the page off. And I don't
think RegisterForEventValidation can work with my situation.
Anybody has idea, what is the solution in ASP.NET 2.0?
--
WWW: http://www.imagestation.com/members/hardywang
ICQ: 3359839
yours Hardy