欢迎光临

木子屋

标题: GridView中查找控件示例

作者: dnawo

日期: 2010-08-09 04:45 PM

分类: Web编程

内容: 复制内容到剪贴板 程序代码<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<int> ids = new List<int>();
for (int i = 1; i <= 3; i++)
ids.Add(i);
GridView1.DataSource = ids;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//注意在GridView1.Rows[index]中才能找到控件
CheckBox chkId = GridView1.Rows[1].FindControl("chkId") as CheckBox;
if (chkId != null)
chkId.Checked = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridView中查找控件示例-Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkId" Text='<%# Container.DataItem %>' runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
</form>
</body>
</html>

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.711 ms

返回

标题: GridView中查找控件示例

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.711 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.898 ms

返回