Home All Groups Group Topic Archive Search About
Author
26 Apr 2005 11:32 AM
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 ();

}

Author
26 Apr 2005 5:51 PM
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
elton_w***@hotmail.com


>-----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
Show quoteHide quote
>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]);
Show quoteHide quote
>
>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 ();
>
>}
>
>
>.
>
Author
27 Apr 2005 5:09 AM
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

Show quoteHide quote
"Elton W" <anonym***@discussions.microsoft.com> wrote in message
news:000501c54a88$9938a080$a501280a@phx.gbl...
> 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
> elton_w***@hotmail.com
>
>
>>-----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 ();
>>
>>}
>>
>>
>>.
>>
Author
27 Apr 2005 5:39 AM
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
Author
27 Apr 2005 1:47 PM
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"></AlternatingItemStyle>
>    <HeaderStyle Font-Bold="True"
HorizontalAlign="Center" ForeColor="White"
>VerticalAlign="Middle"
>     BackColor="#6699CC"></HeaderStyle>
>    <Columns>
>     <asp:ButtonColumn Text="+"
CommandName="SelectProject">
Show quoteHide quote
>      <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);
Show quoteHide quote
>
>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]);
Show quoteHide quote
>
>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
Show quoteHide quote
>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
>
>
>.
>