Salve a tutti,
qualcuno sa dirmi perche' il seguente snippet non funziona se il
buttontype della colonna e' messo a pushbutton anziche' a linkbutton?
Grazie,
Franz.
<%@ Page Language="c#" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e) {
//-- create a data source
DataTable dt = new DataTable();
DataRow dr;
//-- randomly generate some test data
dt.Columns.Add(new DataColumn("String", typeof(string)));
dt.Columns.Add(new DataColumn("Integer", typeof(Int32)));
for (Int32 i = 0; i < 10; i++) {
dr = dt.NewRow();
dr[0] = "Button " + i.ToString();
dr[1] = i;
dt.Rows.Add(dr);
}
//-- bind the data source
Custom.DataSource = dt;
Custom.DataBind();
}
protected void Clicked (Object sender, DataGridCommandEventArgs e) {
Msg.Text = "You clicked Integer " + e.Item.Cells[1].Text;
}
</script>
<html>
<head>
<title>Hungry Minds Chapter 9...</title>
</head>
<body>
[img]logo.gif[/img]
<font face="verdana" size="5">DataGrid Example with the Button Column...</font>
<hr />
<form method="post" runat="server">
<aspataGrid id="Custom" Height="174px" Width="287px" AutoGenerateColumns="False" RunAt="server" OnItemCommand="Clicked">
<HeaderStyle backcolor="#6699CC"></HeaderStyle>
<Columns>
<asp:ButtonColumn ButtonType="LinkButton" DataTextField="String" HeaderText="String"></asp:ButtonColumn>
<asp:BoundColumn DataField="Integer" HeaderText="Numero"></asp:BoundColumn>
</Columns>
</aspataGrid>
<asp:Label id="Msg" runat="server" text="Click a column button."></asp:Label>
</form>
<hr />
</body>
</html>

ataGrid id="Custom" Height="174px" Width="287px" AutoGenerateColumns="False" RunAt="server" OnItemCommand="Clicked">
Rispondi quotando