在Repeater1_DataBinding事件中怎么取Repeater中Label的值 我想实现的功能是:repeater中有一列是“查看详情” 如果这一行数据没有添加详细信息则 “查看详情”下面的按钮时不可用的,如果有则可以点击。 (那位大侠做过类似的功能,麻烦您给贴出来点代码后给个例子。) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 net_lover 于 2010-08-27 16:43:31 编辑 在Repeater1_ItemCommand事件里写实试过了。 不行,要先点击一下,才能发现能不能用。 1楼不是已经写了么,在ItemDataBound事件里就处理掉,而不是在ItemCommand事件里处理。 我把我写的代码给大家贴出来:public partial class anniu : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bind(); } } public void bind() { string sql = "select * from T_x"; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); SqlCommand com = new SqlCommand(sql, con); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = com; da.Fill(ds); this.Repeater1.DataSource = ds; this.Repeater1.DataBind(); } protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { //if (e.CommandName == "look") //{ // //Button bt = ((Button)e.Item.FindControl("but")); // //string aa = Convert.ToString(bt.Text); // //Response.Write(aa); //} } protected void Repeater1_DataBinding(object sender, EventArgs e) { ////这注释的原因是报错。报出:“System.EventArgs”并不包含“Item”的定义 ////Label lb = ((Label)e.Item.FindControl("Lbl")); ////int aa = Convert.ToInt32(lb.Text); //string strsql = "select * from T_xx where ID=" + aa; //SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); //SqlCommand com1 = new SqlCommand(strsql, con1); //DataSet dss = new DataSet(); //SqlDataAdapter daa = new SqlDataAdapter(); //daa.SelectCommand = com1; //daa.Fill(dss); //if (dss.Tables[0].Rows.Count > 0) //{ // Button bu = ((Button)e.Item.FindControl("but")); // bu.Enabled = true; //} //else //{ // Button bu = ((Button)e.Item.FindControl("but")); // bu.Enabled = false; //} } protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { //单步调试的结果是 lb=null Label lb = ((Label)e.Item.FindControl("Lbl")); int aa = Convert.ToInt32(lb.Text); string strsql = "select * from T_xx where ID=" + aa; SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString); SqlCommand com1 = new SqlCommand(strsql, con1); DataSet dss = new DataSet(); SqlDataAdapter daa = new SqlDataAdapter(); daa.SelectCommand = com1; daa.Fill(dss); if (dss.Tables[0].Rows.Count > 0) { Button bu = ((Button)e.Item.FindControl("but")); bu.Enabled = true; } else { Button bu = ((Button)e.Item.FindControl("but")); bu.Enabled = false; } }} 在判断里面给按钮加enabled属性就可以了。按钮.Enabled = false;这是禁用true就是启用 <asp:Label ID="lbl" runat="server" Visible='<%# Check((int)Eval("a")) %>'></asp:Label>protected bool Check(int value){ return true;} 运用js。在后台写一个public方法。 js调用后台方法 两个AJAX怎么互相通讯 就是让第二个AJAX终止掉第一个 如何获取datalist中EditItemTemplate里的控件 ASP的一个小问题 ASP。NET的项目属性在哪 公司又要订明年的专业杂志了,请大家推荐几个认为比较好的WEB开发(FORM开发也可)杂志。当然《程序员》就不用推荐了。推荐者有分。 求教!! 关于弹出网页对话框 和 双击表格获取数据的问题 项目明天就要交付了,但注册这块还没解决,急啊~~~~也没分了 关于vs.net2003中表格的用法 验证window登陆密码(ad密码) 请看我的代码有没有问题?
在Repeater1_ItemCommand事件里写实试过了。 不行,要先点击一下,才能发现能不能用。
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind();
}
}
public void bind()
{ string sql = "select * from T_x";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand com = new SqlCommand(sql, con); DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = com;
da.Fill(ds); this.Repeater1.DataSource = ds;
this.Repeater1.DataBind(); }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//if (e.CommandName == "look")
//{
// //Button bt = ((Button)e.Item.FindControl("but"));
// //string aa = Convert.ToString(bt.Text);
// //Response.Write(aa); //}
}
protected void Repeater1_DataBinding(object sender, EventArgs e)
{
////这注释的原因是报错。报出:“System.EventArgs”并不包含“Item”的定义
////Label lb = ((Label)e.Item.FindControl("Lbl"));
////int aa = Convert.ToInt32(lb.Text); //string strsql = "select * from T_xx where ID=" + aa;
//SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
//SqlCommand com1 = new SqlCommand(strsql, con1);
//DataSet dss = new DataSet();
//SqlDataAdapter daa = new SqlDataAdapter();
//daa.SelectCommand = com1;
//daa.Fill(dss); //if (dss.Tables[0].Rows.Count > 0)
//{
// Button bu = ((Button)e.Item.FindControl("but"));
// bu.Enabled = true;
//}
//else
//{
// Button bu = ((Button)e.Item.FindControl("but"));
// bu.Enabled = false;
//} }
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//单步调试的结果是 lb=null
Label lb = ((Label)e.Item.FindControl("Lbl"));
int aa = Convert.ToInt32(lb.Text); string strsql = "select * from T_xx where ID=" + aa;
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand com1 = new SqlCommand(strsql, con1);
DataSet dss = new DataSet();
SqlDataAdapter daa = new SqlDataAdapter();
daa.SelectCommand = com1;
daa.Fill(dss); if (dss.Tables[0].Rows.Count > 0)
{
Button bu = ((Button)e.Item.FindControl("but"));
bu.Enabled = true;
}
else
{
Button bu = ((Button)e.Item.FindControl("but"));
bu.Enabled = false;
}
}
}
按钮.Enabled = false;这是禁用true就是启用
='<%# Check((int)Eval("a")) %>'></asp:Label>
protected bool Check(int value)
{
return true;
}