在gridview中隐藏数据集值 [英] Hide Dataset value in gridview

查看:106
本文介绍了在gridview中隐藏数据集值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个带有两个数据适配器的数据集。两个数据集都是合并的。我不想在gridview中显示第一个数据集值。请给我代码。



If I have two dataset with two dataadapters.Both dataset are merge. I dont want to show the first dataset value in gridview .please give me code.

string pageid = "";
            foreach (GridViewRow grrow in Gridheader.Rows)
            {
                CheckBox chk = (CheckBox)grrow.FindControl("chk1");
                if (chk.Checked == true)
                {
                    Label id = (Label)grrow.FindControl("lblpageid");
                    pageid += id.Text.ToString() + "','";
                    btnSave2.Visible = true;
                }
            }
            string query = "SELECT PageAuthentication.PageName,PageAuthentication.Page_ID FROM PageAuthentication INNER JOIN PageUserAuthorization ON PageAuthentication.Page_ID = PageUserAuthorization.Page_ID WHERE PageUserAuthorization.Type_ID = '" + ddlSelectUsertype.SelectedValue + "' and PageAuthentication.PageParent_ID in ('" + pageid.TrimEnd(',').Replace(" ' ", " ") + "')";
            string query1 = "SELECT PageAuthentication.PageName,PageAuthentication.Page_ID FROM PageAuthentication INNER JOIN PageUserAuthorization ON PageAuthentication.Page_ID = PageUserAuthorization.Page_ID WHERE PageUserAuthorization.Type_ID = '" + ddlSelectUsertype.SelectedValue + "' and PageAuthentication.Page_ID in('" + pageid.TrimEnd(',').Replace(" ' ", " ") + "')";
            adap = new SqlDataAdapter(query, con);
            SqlDataAdapter adap1 = new SqlDataAdapter(query1, con);
            ds = new DataSet();
            DataSet ds1 = new DataSet();
            adap.Fill(ds);
            adap1.Fill(ds1);
            ds.Merge(ds1);
            Gridpage.DataSource =ds ;
            Gridpage.DataBind();







我想在gridview中隐藏ds1的值请给我代码。




I want to hide values of ds1 in gridview please give me code.

推荐答案

设置AutoGenerateColumns =False并使用BoundField生成列分配数据集列作为数据字段值并且可见true.Mention HeaderText作为您的网格列name.all最好的示例代码在这里:



< asp:gridview id =grvComprunat =serverwidth =100%autogeneratecolumns =假xmlns:asp =#unknown>

BorderStyle =SolidCssClass =GridDataShowHeader =true

BorderColor =Black字体 - Size =X-SmallCellPadding =0

ShowHeaderWhenEmpty =True>

< columns>

< asp:boundfield datafield =CompShrtDescheadertext =Companyreadonly =Truesortexpression =Company>

< headerstyle backcolor =# 8C6A21font-bold =Trueforecolor =Whitewidth =26%>

CssClass =CaptionTextBorderColor =WhiteBorderStyle =Solid/>

< itemstyle width =75%>



< asp:templatefield>

< headerstyle horizo​​ntalalign =Leftwidth =5%backcolor =#8C6A21font-bold =True>

ForeColor =WhiteBorderColor =White

BorderStyle =Solid字体名称=Verdana>
set AutoGenerateColumns="False" and Use BoundField to generate column assign dataset column as datafield value and visible true.Mention HeaderText as your grid column name.all the best sample code is here:

<asp:gridview id="grvComp" runat="server" width="100%" autogeneratecolumns="False" xmlns:asp="#unknown">
BorderStyle="Solid" CssClass="GridData" ShowHeader="true"
BorderColor="Black" Font-Size="X-Small" CellPadding="0"
ShowHeaderWhenEmpty="True">
<columns>
<asp:boundfield datafield="CompShrtDesc" headertext="Company" readonly="True" sortexpression="Company">
<headerstyle backcolor="#8C6A21" font-bold="True" forecolor="White" width="26%">
CssClass="CaptionText" BorderColor="White" BorderStyle="Solid"/>
<itemstyle width="75%">

<asp:templatefield>
<headerstyle horizontalalign="Left" width="5%" backcolor="#8C6A21" font-bold="True">
ForeColor="White" BorderColor="White"
BorderStyle="Solid" Font-Names="Verdana" >


在网格的数据绑定事件上

on the Databound event of the grid
protected void gridview1_DataBound(object sender, EventArgs e)
{
     GridView cgvtmp = (GridView)sender;
     cgvtmp.Columns[x].visible = false;
}



其中x是你要隐藏的栏目





抱歉误读了这个问题,你想只显示那些在ds而不是在ds1中的行?



然后在sql中设置一个标志

在RowDatabound事件中检查当前行是否被标记,如果是,则隐藏该行




where x is the column you wish to hide


[edit] sorry misread the question, you want to display only those rows that are in ds and not in ds1?

then set a flag in the sql
in the RowDatabound event check if the current row is flagged, if it is then hide that row

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
        {
          //find flag here and hide e.Row if required
          
        }
}


这篇关于在gridview中隐藏数据集值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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