Columns are displayed twice

P

Phani

I have two datagrids .... after handling the click event in one datagrid
..... using its data i query the database and get the data for the second
datagrid

in both the grids i am generating the columns dynamically

the problem is in the second datagrid the columns are appearing twice

i dont know y ??

like if "a |b |c|" are the actual columns to be displayed

they r displayed as

a|b|c|a|b|c|



can anyone help me???/

this is my onitemcommand code

protected void Item_click(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

int key = Convert.ToInt32 (DataGrid1.DataKeys[e.Item.ItemIndex]);

SqlDataReader read = project.GetSingleProject (key);

if(read.Read ())

{

string name = read["ProjectName"].ToString ();

Label1.Text = "Tasks Related to "+name;

}

TasksDB task=new TasksDB ();

DataSet ds = task.GetTasks (key);

DataGrid2.DataSource =ds;

DataGrid2.AutoGenerateColumns =false;

foreach(DataColumn c in ds.Tables [0].Columns )

DataGrid2.Columns .Add (CreateBoundColumn(c));

DataGrid2.DataBind ();

}
 
E

Elton W

Hi Phani,

It seems you set the datagrid's AutoGenerateColumns =
True. And you also create some columns manually. If so,
just set AutoGenerateColumns = false.

HTH

Elton Wang
(e-mail address removed)
 
P

Phani

hi Elton

i have set that off but the same problem persists ....
anyway thanks for ur reply .... and do reply me if u find any solution to
this

regards
Phani

Elton W said:
Hi Phani,

It seems you set the datagrid's AutoGenerateColumns =
True. And you also create some columns manually. If so,
just set AutoGenerateColumns = false.

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----
I have two datagrids .... after handling the click event in one datagrid
..... using its data i query the database and get the data for the second
datagrid

in both the grids i am generating the columns dynamically

the problem is in the second datagrid the columns are appearing twice

i dont know y ??

like if "a |b |c|" are the actual columns to be displayed

they r displayed as

a|b|c|a|b|c|



can anyone help me???/

this is my onitemcommand code

protected void Item_click(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

int key = Convert.ToInt32 (DataGrid1.DataKeys [e.Item.ItemIndex]);

SqlDataReader read = project.GetSingleProject (key);

if(read.Read ())

{

string name = read["ProjectName"].ToString ();

Label1.Text = "Tasks Related to "+name;

}

TasksDB task=new TasksDB ();

DataSet ds = task.GetTasks (key);

DataGrid2.DataSource =ds;

DataGrid2.AutoGenerateColumns =false;

foreach(DataColumn c in ds.Tables [0].Columns )

DataGrid2.Columns .Add (CreateBoundColumn(c));

DataGrid2.DataBind ();

}


.
 
P

Phani

This is my first datagrid .....

<asp:datagrid id="DataGrid1" runat="server" Width="100%"
AutoGenerateColumns="False" Font-Names="Tahoma" Font-Size="Smaller"
AllowSorting="True" OnItemCommand="Item_click">
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White"
VerticalAlign="Middle"
BackColor="#6699CC"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="+" CommandName="SelectProject">
<HeaderStyle Width="20px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"
VerticalAlign="Middle"></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid>

This is my second datagrid ......

<asp:DataGrid id="DataGrid3" runat="server" AutoGenerateColumns="False"
Width="100%">
<HeaderStyle Font-Size="Smaller" Font-Bold="True" ForeColor="White"
BackColor="#660000"></HeaderStyle>
</asp:DataGrid>

And the code behind is as follows ....

private void Page_Load(object sender, System.EventArgs e)

{

DataSet ds1 = project.GetProjects (Context.User.Identity.Name);

DataGrid1.DataSource =ds1;

DataGrid1.DataKeyField ="ProjectId";

if(Context.User.IsInRole ("Members"))

{

foreach(DataColumn c in ds1.Tables [0].Columns )

{

if(c.ColumnName =="ProjectId" || c.ColumnName =="ProjectCreationDate" ||
c.ColumnName =="ProjectCreatorId" || c.ColumnName =="StatusId")

continue;

DataGrid1.Columns .Add (CreateBoundColumn(c));

}

}

else

{

foreach(DataColumn c in ds1.Tables [0].Columns )

{

DataGrid1.Columns .Add (CreateBoundColumn(c));

}

}

DataGrid1.DataBind ();

}

private BoundColumn CreateBoundColumn(DataColumn c)

{

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

return Column;

}

protected void Item_click(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

int key = Convert.ToInt32 (DataGrid1.DataKeys[e.Item.ItemIndex]);

SqlDataReader read = project.GetSingleProject (key);

if(read.Read ())

{

string name = read["ProjectName"].ToString ();

Label1.Text = "Tasks Related to "+name;

}

TasksDB task=new TasksDB ();

DataSet ds = task.GetTasks (key);

DataGrid3.AutoGenerateColumns =false;

if(Context.User.IsInRole ("Members"))

{

foreach(DataColumn c in ds.Tables [0].Columns )

{

if(c.ColumnName =="TaskId" || c.ColumnName =="TaskCreationDate" ||
c.ColumnName =="TaskCreatorId" || c.ColumnName =="StatusId")

continue;

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

DataGrid3.Columns .Add (Column);

}

}

else

{

foreach(DataColumn c in ds.Tables [0].Columns )

{

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

DataGrid3.Columns .Add (Column);

}

}

DataGrid3.DataSource =ds;

DataGrid3.DataBind ();

}



And the problem is ...... the columns are displayed twice in the second
datagrid ....

someone help me out please ....

eg; Actual columns to be displayed ..... A B C

Displayed columns ....... A B C A B C



regards

Phani
 
E

Elton W

Hi Phani,

You can set breakpoint in code, and trace running to see
what happens.

HTH

Elton

-----Original Message-----
This is my first datagrid .....

<asp:datagrid id="DataGrid1" runat="server" Width="100%"
AutoGenerateColumns="False" Font-Names="Tahoma" Font- Size="Smaller"
AllowSorting="True" OnItemCommand="Item_click">
<AlternatingItemStyle
BackColor="Gainsboro"> said:
<HeaderStyle Font-Bold="True"
HorizontalAlign="Center" ForeColor="White"
VerticalAlign="Middle"
BackColor="#6699CC"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="+" CommandName="SelectProject">
<HeaderStyle Width="20px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"
VerticalAlign="Middle"></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid>

This is my second datagrid ......

<asp:DataGrid id="DataGrid3" runat="server" AutoGenerateColumns="False"
Width="100%">
<HeaderStyle Font-Size="Smaller" Font-Bold="True" ForeColor="White"
BackColor="#660000"></HeaderStyle>
</asp:DataGrid>

And the code behind is as follows ....

private void Page_Load(object sender, System.EventArgs e)

{

DataSet ds1 = project.GetProjects (Context.User.Identity.Name);

DataGrid1.DataSource =ds1;

DataGrid1.DataKeyField ="ProjectId";

if(Context.User.IsInRole ("Members"))

{

foreach(DataColumn c in ds1.Tables [0].Columns )

{

if(c.ColumnName =="ProjectId" || c.ColumnName =="ProjectCreationDate" ||
c.ColumnName =="ProjectCreatorId" || c.ColumnName =="StatusId")

continue;

DataGrid1.Columns .Add (CreateBoundColumn(c));

}

}

else

{

foreach(DataColumn c in ds1.Tables [0].Columns )

{

DataGrid1.Columns .Add (CreateBoundColumn(c));

}

}

DataGrid1.DataBind ();

}

private BoundColumn CreateBoundColumn(DataColumn c)

{

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

return Column;

}

protected void Item_click(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

int key = Convert.ToInt32 (DataGrid1.DataKeys [e.Item.ItemIndex]);

SqlDataReader read = project.GetSingleProject (key);

if(read.Read ())

{

string name = read["ProjectName"].ToString ();

Label1.Text = "Tasks Related to "+name;

}

TasksDB task=new TasksDB ();

DataSet ds = task.GetTasks (key);

DataGrid3.AutoGenerateColumns =false;

if(Context.User.IsInRole ("Members"))

{

foreach(DataColumn c in ds.Tables [0].Columns )

{

if(c.ColumnName =="TaskId" || c.ColumnName =="TaskCreationDate" ||
c.ColumnName =="TaskCreatorId" || c.ColumnName =="StatusId")

continue;

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

DataGrid3.Columns .Add (Column);

}

}

else

{

foreach(DataColumn c in ds.Tables [0].Columns )

{

BoundColumn Column=new BoundColumn ();

Column.DataField =c.ColumnName ;

Column.HeaderText =c.ColumnName ;

DataGrid3.Columns .Add (Column);

}

}

DataGrid3.DataSource =ds;

DataGrid3.DataBind ();

}



And the problem is ...... the columns are displayed twice in the second
datagrid ....

someone help me out please ....

eg; Actual columns to be displayed ..... A B C

Displayed columns ....... A B C A B C



regards

Phani


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top