前台:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"/>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="checkbox1" runat="server" ToolTip='<%#Eval("id") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>后台:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
void BindGridView()
{
this.GridView1.DataSource = GetTable();
this.GridView1.DataBind();
}
DataTable GetTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
string[] str = new string[20];
for (int i = 0; i < str.Length; i++)
{
str[i] = i.ToString();
}
for (int j = 0; j < str.Length; j++)
{
DataRow row = dt.NewRow();
row["id"] = str[j];
dt.Rows.Add(row);
}
return dt;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox cb = e.Row.FindControl("checkbox1") as CheckBox;
if (cb != null)
{
if (cb.ToolTip == "1")
{
cb.Checked = true;
}
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"/>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="checkbox1" runat="server" ToolTip='<%#Eval("id") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>后台:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
void BindGridView()
{
this.GridView1.DataSource = GetTable();
this.GridView1.DataBind();
}
DataTable GetTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
string[] str = new string[20];
for (int i = 0; i < str.Length; i++)
{
str[i] = i.ToString();
}
for (int j = 0; j < str.Length; j++)
{
DataRow row = dt.NewRow();
row["id"] = str[j];
dt.Rows.Add(row);
}
return dt;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox cb = e.Row.FindControl("checkbox1") as CheckBox;
if (cb != null)
{
if (cb.ToolTip == "1")
{
cb.Checked = true;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货