在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方法。 如何把数据库中的数组遍历到<div>中 存储显示换行 ASP.NET下载txt文件,FF使用正常,可是IE却是将页面的源代码下载下来了! 关于配置文件的继承 高难度问题,请高手解决,先谢谢 asp项目部署 怎么封装类啊~~呜~~我封装地报错~~~~帮我一下,谢谢了 新闻图片无法显示 简单的表单提交过程中的编码问题 请教一个小问题!!进有分 验证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;
}