62,244
社区成员




<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="C1">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="C2" DataField="Name" />
<asp:TemplateField HeaderText="C3">
<ItemTemplate>
<asp:DropDownList ID="ddl" runat="server">
<asp:ListItem Text="ADSL" Value="ADSL"></asp:ListItem>
<asp:ListItem Text="3G" Value="3G"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//必须要实现IPostBackEventHandler接口
public partial class WebForm1 : System.Web.UI.Page, IPostBackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
//数据
DataFromDataBase d1 = new DataFromDataBase();
DataFromDataBase d2 = new DataFromDataBase();
d1.Name = "N1";
d2.Name = "N2";
DataFromDataBase[] ds = new DataFromDataBase[] { d1, d2 };
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox cb = e.Row.FindControl("CheckBox1") as CheckBox;
string script = ClientScript.GetPostBackEventReference(this.Page, "");
cb.Attributes.Add("onclick", script);
}
}
public void RaisePostBackEvent(string eventArgument)
{
A classA = new A();
classA.IsInUse();
}
}
public class A
{
public void IsInUse()
{
}
}
public class DataFromDataBase
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}