如何根据gridview中的条件隐藏行

编程入门 行业动态 更新时间:2024-10-08 02:19:07
本文介绍了如何根据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中的条件隐藏行

本文发布于:2023-11-30 12:42:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!