本文介绍了如何根据gridview中的条件隐藏行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
filename path Status ----------------------------- 1.txt D:\JI\1.txt E a.txt D:\JI\a.txt D b.txt D:\JI\b.txt E
This is my datatable values.I want to bind this value to a gridview.Before that I want to remove / hide the the rows which having the status as 'D'.I used onRowdatabound event ,but its not working .please help dtTemSec = (DataTable)ViewState["SecDetails"]; GridImport.DataSource = dtTemSec; GridImport.DataBind();
推荐答案
BoundField 如果您使用 BoundField ,则下面的内容会起作用。 BoundField Something like below would work, if you have used BoundField. private void GridImport_RowDataBound(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[2].Text.Equals("D")) e.Row.Visible = false; } }
TemplateField 如果值在 TemplateField ,然后你需要找到那个控件,然后尝试比较文本......假设里面有一个 TextBox code> TemplateField ,其中值已固定。
TemplateField If the value is inside a TemplateField, then you need to find that control and then try to compare the text like... Suppose there is a TextBox inside TemplateField, where the value is fastened.
private void GridImport_RowDataBound(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtStatus = (TextBox)rw.FindControl("txStatus"); if (txtStatus.Text.Equals("D")) e.Row.Visible = false; }
GridImport.DataSource = dtTemSec.AsEnumerable() .Where(x => x.Field<string>("Status") != "D") .CopyToDataTable(); GridImport.DataBind();
更多推荐
如何根据gridview中的条件隐藏行
发布评论