Click here to Skip to main content
15,921,279 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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();



I want to hide values of ds1 in gridview please give me code.
Posted
Updated 17-Jul-13 4:16am
v4
Comments
Ravi shekahr 16-Mar-12 1:52am    
Please Help me .its an urgent.
Ravi shekahr 16-Mar-12 2:23am    
Please Give me code sir...
Sandeep Mewara 10-May-12 8:33am    
Not clear on what are you trying to ask. You have two dataset. Set the one you want to.

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" >
 
Share this answer
 
on the Databound event of the grid
C#
protected void gridview1_DataBound(object sender, EventArgs e)
{
     GridView cgvtmp = (GridView)sender;
     cgvtmp.Columns[x].visible = false;
}

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900