我要在gridview中的模板列中加入一个退房的button,条件是如果已经退房了,就不在gridview上面显示,如果没有退房的话,就在上面显示。
请问怎么实现这个功能啊?
请问怎么实现这个功能啊?
解决方案 »
- |zyciis| 如何让text的onblur事件执行fcous和select事件
- 请教一个UrlRewrite的问题
- 我的工具栏里没有 WebBrowser控件
- 急急急---使用ajax填充Repeater
- 页面只能在框架内打开的问题,顶者有分
- 为什么"If Request.Cookies("CQC_UserLev").Value Is Nothing Then"语句无效?
- 在asp.net中怎么获取服务器的时间
- 关于asp.net的socket问题,有点难度,如果解决可再加分。
- global.aspx
- 如何对DropDownList的Text和value值实现分别数据绑定?
- asp.net回传数据大,页面经常卡住,何解?
- 各位如何判断IDataReader 读取是否包含某字段
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
if(e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = e.Row.FindControl("buttonid") as Button;
if("已经退房")
{
btn.Visible = false;
}
}
}
GridView1.DataBind();
//后面加上
for(int i=0;i<GridView1.Rows.Count;i++)
{
Button tn=(Button)GridView1.Rows[i].FindControl("退房按钮ID");
if(dt.Rows[i]["退房列"].ToString()=="退房")
{
tn.Visible=false;
}
}
GridViewRow gr = this.GridView1.Rows[GridView1.SelectedRow.RowIndex];
Button btn = (Label)gr.FindControl("buttonID");这样就可以得到Button控件了
改为:
Button btn = (Button)gr.FindControl("buttonID");
<asp:TemplateField HeaderText="删除">
</asp:TemplateField>
后台: protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lbl_Del = new Label();
//e.Row.Cells[7].Text添加你需要的那个状态,然后在
/* protected void myGridView_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[7].Visible = false;
}
*/
不显示,但是可以每次读取数据库的状态,然后加载下面的代码
if (e.Row.Cells[7].Text == "1")
{
lbl_Del.Text = “<input type='Button' text='btn' >";
e.Row.Cells[n].Controls.Add(lbl_Del); }
不显示,但是可以每次读取数据库的状态,然后加载下面的代码
if (e.Row.Cells[7].Text == "0")
{
lbl_Del.Text = “<input type='XXXX' text='btn' >";
e.Row.Cells[n].Controls.Add(lbl_Del); }
}
看懂没?