Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Columns are displayed twice

Reply
Thread Tools

Columns are displayed twice

 
 
Phani
Guest
Posts: n/a
 
      04-26-2005
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 ();

}


 
Reply With Quote
 
 
 
 
Elton W
Guest
Posts: n/a
 
      04-26-2005
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
http://www.velocityreviews.com/forums/(E-Mail 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.DataGridCommandEventArg s 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 ();
>
>}
>
>
>.
>

 
Reply With Quote
 
 
 
 
Phani
Guest
Posts: n/a
 
      04-27-2005
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" <(E-Mail Removed)> wrote in message
news:000501c54a88$9938a080$(E-Mail Removed)...
> 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 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.DataGridCommandEventAr gs 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 ();
>>
>>}
>>
>>
>>.
>>



 
Reply With Quote
 
Phani
Guest
Posts: n/a
 
      04-27-2005
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 ......

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

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


 
Reply With Quote
 
Elton W
Guest
Posts: n/a
 
      04-27-2005
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"></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 ......
>
> <aspataGrid id="DataGrid3" runat="server"

AutoGenerateColumns="False"
>Width="100%">
> <HeaderStyle Font-Size="Smaller" Font-Bold="True"

ForeColor="White"
>BackColor="#660000"></HeaderStyle>
> </aspataGrid>
>
>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.DataGridCommandEventArg s 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
>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Japanese Text not displayed on Image Generated by Servlet on winXP, Linux but displayed on Win2000 boney Java 1 12-15-2006 02:24 PM
twice(twice(x)) Kiuhnm C++ 2 04-01-2006 04:41 PM
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
ActionErrors displayed twice beenamore@gmail.com Java 0 06-13-2005 04:15 PM
convert rows to columns and columns to rows helpful sql ASP .Net 0 05-19-2005 06:03 PM



Advertisments