如何在gridview行为空时禁用链接按钮链接 [英] how to disable link button link when gridview row is empty
问题描述
在运行模式下如下
链接(Headertext)可用日期(Headertext)
链接按钮27 2015年5月
链接按钮2015年6月29日
链接按钮2015年7月25日
链接按钮
链接按钮29 2015年5月
链接按钮2015年6月26日
链接按钮2015年7月24日
链接按钮
i不想显示gridview行为空时的链接按钮。
因为4throw和8throw是空的。
我怎么能用c#。
In run mode as follows
Link(Headertext) Availabledate(Headertext)
Link button 27 may 2015
Link button 29 jun 2015
Link button 25 jul 2015
Link button
Link button 29 may 2015
Link button 26 jun 2015
Link button 24 jul 2015
Link button
i dont want to show Link button when gridview row is empty.
because 4throw and 8throw is empty.
for that how can i do in c#.
推荐答案
//请使用单元格格式化事件并删除不必要的行。
//please use cell formatting event and remove un necessary row.
private void grdview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
try
{
if (this.grdview1.Columns[e.ColumnIndex].Name == "Availabledate")
{
if (this.grdview1.Rows[e.RowIndex] != null)
{
if (string.IsNullOrEmpty(this.grdview1["Availabledate", e.RowIndex].Value.ToString()) )
{
this.grdview1.Rows.RemoveAt(e.RowIndex);
}
}
}
}
catch(Exception ex)
{
}
}
您应该使用RowDatabound事件并检查行(linkbutton值)是否为空,然后将false设置为您的linkbutton。
例如:
You should use RowDatabound event and check if the row(linkbutton value) is empty then set visible false to your linkbutton.
example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnk= e.Row.FindControl("yourlinkbuttonID") as LinkButton;
//assuming the text9 27 may 2015) is written on link button
if (lnk.Text == "")
{
lnk.Visible = false;
}
}
}
private void grdview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
try
{
if (this.grdview1.Columns[e.ColumnIndex].Name == "Availabledate")
{
if (this.grdview1.Rows[e.RowIndex] != null)
{
if (string.IsNullOrEmpty(this.grdview1["Availabledate", e.RowIndex].Value.ToString()) )
{
this.grdview1.Rows.RemoveAt(e.RowIndex);
}
}
}
}
catch(Exception ex)
{
}
}
这篇关于如何在gridview行为空时禁用链接按钮链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!