如何在ASP.NET C#中隐藏具有条件的GridView行? [英] How to hide GridView Rows with conditions in ASP.NET C#?

查看:49
本文介绍了如何在ASP.NET C#中隐藏具有条件的GridView行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在gridview中隐藏选定的日期行。

来源查看:

I want to hide selected day rows in gridview.
Source View:

  <td>
<asp:Button ID="Button1" runat="server" Text="Show" Font-Bold="True"

onclick="Button1_Click" />
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

<Columns>
<asp:TemplateField HeaderText="Selection">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Days">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("DayName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time">
<ItemTemplate>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>



代码视图(Default.aspx.cs):


Code View( Default.aspx.cs):

 protected void Button1_Click(object sender, EventArgs e)
{
String[] arr = new String[6];
arr[0] = "Wednesday";
arr[1] = "Friday";
arr[2] = "Saturday";
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\TestDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
DataTable DT = new DataTable();
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select *from day", con);
da.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
catch (Exception pm)
{

}
finally
{
con.Close();
}
}





输出:



但我想隐藏那些我选择粉红色背景数组值的行。

ie,



Output:

But I want to hide those rows which I selected pink background array values.
i.e,

 String[] arr = new String[6];
arr[0] = "Wednesday";
arr[1] = "Friday";
arr[2] = "Saturday";



所以,只在gridview中显示星期一,星期二,星期四,星期日行。



请帮助我。


So, only show Monday, Tuesday, Thursday, Sunday rows in gridview.

Please Help Me.

推荐答案

为什么你要坐在那里坐着,结婚,炸成阵...使用数据表过滤器例如:





da.Fill(DT);



DataTable dt2 = DT.Select((Dayname ='SUNDAY')和(Dayname ='MONDAY'))。CopyToDataTable();



i我不确定它的语法。 .try this
why you are take that sat,wed,fry in array...use Datatable filter eg:


da.Fill(DT);

DataTable dt2 = DT.Select("(Dayname= 'SUNDAY') AND (Dayname= 'MONDAY')").CopyToDataTable();

i am not sure of it's syntax ..try this


这篇关于如何在ASP.NET C#中隐藏具有条件的GridView行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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