当gridview行为空时,如何在gridview中添加链接按钮 [英] how to add link button in gridview when gridview row is empty

查看:62
本文介绍了当gridview行为空时,如何在gridview中添加链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gridview中的运行模式如下



预约日期



2015年5月27日
2015年5月30日

2015年6月

空行

2015年5月25日

28 may 2015年

2015年5月

空行



在上面的gridview for empty row中我要显示链接按钮。



我怎样才能在asp.net中使用c#。

解决方案

试一试

行数据绑定检查行或单元格是空的

在该单元格中添加新的链接按钮控件



protected void GridView1_DataBound(对象发送者,GridViewRowEv entArgs e)

{

if(e.Row.RowType == DataControlRowType.DataRow)

{

if(string.IsNullOrEmpty(e.Row.Cells [0] .Text))

{

//或有时候没有休息空间 -  会更好用

按钮btn =新按钮();

btn.Text =查看更多;

e.Row.Cells [0] .Controls.Add(btn);

}

}

}

In run mode in gridview as follows

Appointment date

27 may 2015
30 may 2015
1 june 2015
empty row
25 may 2015
28 may 2015
30 may 2015
empty row

In the above gridview for empty row i want to display link button.

for that how can i do in asp.net using c#.

解决方案

Try this
on row databound check the row or cell is empty
add new link button control in that cell

protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(string.IsNullOrEmpty(e.Row.Cells[0].Text))
{
// Or sometimes a no break space -  will work better
Button btn= new Button();
btn.Text = "view more";
e.Row.Cells[0].Controls.Add(btn);
}
}
}


这篇关于当gridview行为空时,如何在gridview中添加链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆