how to build a dynamic datagrid

S

sysdesigner

Hi,
We have several sets of report data that we want to be able to edit from one
editable datagrid. We are storing the column heading names in the database
and want the aspx datagrid to be built dynamically from the data in the
database.

Basically we want to have one aspx page for all of the reports instead of
one aspx page for each report.

Please help :)
Shawn
 
S

Sonu Kapoor

Why does it need to be dynamic? Creating dynamic datagrids isnt that easy and
can lead sometimes to many problems.

You could simply use a normal datagrid and pass your storedprocedure to it.
Just leave autogeneratecolumns to true and it will even build the columns for
you based on the stored procedure result.

How does that sound?
--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/
 
S

sysdesigner

Maybe "dynamic" wasn't the right word. We want the columns to change based
on the dataset like you suggested. Below is the aspx code for one of the
templates. We will need to build a dataset because the data is normalized,
so do you suggest building that from the stored procedure? Also, how will we
be able to use the validation controls?

Thanks,
Shawn

---------------------------------------------------------------------------------
<asp:TemplateColumn HeaderText="Caretaker Name">
<ItemTemplate><asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.CTKR_NM") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"></asp:RequiredFieldValidator>
<asp:TextBox id=txtCaretakerAbuseCnt runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.CTKR_ABUS_CT") %>'>
</asp:TextBox>
<asp:RegularExpressionValidator id="Regularexpressionvalidator2"
runat="server" ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"
ValidationExpression="^\d{1}$|^\d{2}$|^[1][0-1][0-5]$"></asp:RegularExpressionValidator> </EditItemTemplate>
</asp:TemplateColumn
-------------------------------------------------------------------------------------------------


Sonu Kapoor said:
Why does it need to be dynamic? Creating dynamic datagrids isnt that easy and
can lead sometimes to many problems.

You could simply use a normal datagrid and pass your storedprocedure to it.
Just leave autogeneratecolumns to true and it will even build the columns for
you based on the stored procedure result.

How does that sound?
--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/


sysdesigner said:
Hi,
We have several sets of report data that we want to be able to edit from one
editable datagrid. We are storing the column heading names in the database
and want the aspx datagrid to be built dynamically from the data in the
database.

Basically we want to have one aspx page for all of the reports instead of
one aspx page for each report.

Please help :)
Shawn
 
S

Sonu Kapoor

When you have AutoGenerateCOlumns set to true, then it will build the
datagrid columns based on the dataset. Because you already know what columns
you want to see, it is a good idea to return only these columns from the
stored procedure. I am assuimg that the data is returned as well from the
database?

I am not sure how to that all with the validation controls, but I am
thinking that you might have to add these validation controls in the
ItemCreated at run time. However I am not sure if you can do that. Usually
when autogeneratecolumns is set to true, then the column collection is 0. You
will have to try that out.


--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/


sysdesigner said:
Maybe "dynamic" wasn't the right word. We want the columns to change based
on the dataset like you suggested. Below is the aspx code for one of the
templates. We will need to build a dataset because the data is normalized,
so do you suggest building that from the stored procedure? Also, how will we
be able to use the validation controls?

Thanks,
Shawn

---------------------------------------------------------------------------------
<asp:TemplateColumn HeaderText="Caretaker Name">
<ItemTemplate><asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.CTKR_NM") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"></asp:RequiredFieldValidator>
<asp:TextBox id=txtCaretakerAbuseCnt runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.CTKR_ABUS_CT") %>'>
</asp:TextBox>
<asp:RegularExpressionValidator id="Regularexpressionvalidator2"
runat="server" ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"
ValidationExpression="^\d{1}$|^\d{2}$|^[1][0-1][0-5]$"></asp:RegularExpressionValidator> </EditItemTemplate>
</asp:TemplateColumn>
-------------------------------------------------------------------------------------------------


Sonu Kapoor said:
Why does it need to be dynamic? Creating dynamic datagrids isnt that easy and
can lead sometimes to many problems.

You could simply use a normal datagrid and pass your storedprocedure to it.
Just leave autogeneratecolumns to true and it will even build the columns for
you based on the stored procedure result.

How does that sound?
--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/


sysdesigner said:
Hi,
We have several sets of report data that we want to be able to edit from one
editable datagrid. We are storing the column heading names in the database
and want the aspx datagrid to be built dynamically from the data in the
database.

Basically we want to have one aspx page for all of the reports instead of
one aspx page for each report.

Please help :)
Shawn
 
S

sysdesigner

I found this article that shows how...

Creating DataGrid Templated Columns Dynamically - Part I
http://www.dotnetbips.com/displayarticle.aspx?id=84


~Shawn


Sonu Kapoor said:
When you have AutoGenerateCOlumns set to true, then it will build the
datagrid columns based on the dataset. Because you already know what columns
you want to see, it is a good idea to return only these columns from the
stored procedure. I am assuimg that the data is returned as well from the
database?

I am not sure how to that all with the validation controls, but I am
thinking that you might have to add these validation controls in the
ItemCreated at run time. However I am not sure if you can do that. Usually
when autogeneratecolumns is set to true, then the column collection is 0. You
will have to try that out.


--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/


sysdesigner said:
Maybe "dynamic" wasn't the right word. We want the columns to change based
on the dataset like you suggested. Below is the aspx code for one of the
templates. We will need to build a dataset because the data is normalized,
so do you suggest building that from the stored procedure? Also, how will we
be able to use the validation controls?

Thanks,
Shawn

---------------------------------------------------------------------------------
<asp:TemplateColumn HeaderText="Caretaker Name">
<ItemTemplate><asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.CTKR_NM") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"></asp:RequiredFieldValidator>
<asp:TextBox id=txtCaretakerAbuseCnt runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.CTKR_ABUS_CT") %>'>
</asp:TextBox>
<asp:RegularExpressionValidator id="Regularexpressionvalidator2"
runat="server" ErrorMessage="Enter a number between 0-120"
ControlToValidate="txtCaretakerAbuseCnt"
ValidationExpression="^\d{1}$|^\d{2}$|^[1][0-1][0-5]$"></asp:RegularExpressionValidator> </EditItemTemplate>
</asp:TemplateColumn>
-------------------------------------------------------------------------------------------------


Sonu Kapoor said:
Why does it need to be dynamic? Creating dynamic datagrids isnt that easy and
can lead sometimes to many problems.

You could simply use a normal datagrid and pass your storedprocedure to it.
Just leave autogeneratecolumns to true and it will even build the columns for
you based on the stored procedure result.

How does that sound?
--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/


:

Hi,
We have several sets of report data that we want to be able to edit from one
editable datagrid. We are storing the column heading names in the database
and want the aspx datagrid to be built dynamically from the data in the
database.

Basically we want to have one aspx page for all of the reports instead of
one aspx page for each report.

Please help :)
Shawn
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top