how to build a dynamic datagrid

Discussion in 'ASP .Net Datagrid Control' started by sysdesigner, Jun 17, 2005.

  1. sysdesigner

    sysdesigner Guest

    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
    sysdesigner, Jun 17, 2005
    #1
    1. Advertising

  2. sysdesigner

    Sonu Kapoor Guest

    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" wrote:

    > 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
    Sonu Kapoor, Jun 17, 2005
    #2
    1. Advertising

  3. sysdesigner

    sysdesigner Guest

    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" wrote:

    > 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" wrote:
    >
    > > 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
    sysdesigner, Jun 17, 2005
    #3
  4. sysdesigner

    Sonu Kapoor Guest

    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" wrote:

    > 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" wrote:
    >
    > > 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" wrote:
    > >
    > > > 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
    Sonu Kapoor, Jun 17, 2005
    #4
  5. sysdesigner

    sysdesigner Guest

    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" wrote:

    > 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" wrote:
    >
    > > 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" wrote:
    > >
    > > > 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" wrote:
    > > >
    > > > > 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
    sysdesigner, Jun 21, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vagif Abilov
    Replies:
    2
    Views:
    562
    Vagif Abilov
    Jul 7, 2004
  2. Pedro Mir
    Replies:
    2
    Views:
    436
    Winista
    Jun 20, 2006
  3. Nicolas Lehuen
    Replies:
    3
    Views:
    714
    Nicolas Lehuen
    Jan 28, 2004
  4. =?Utf-8?B?cGF0cmlja2RyZA==?=

    datagrid custom (dynamic) pager build at runtime?

    =?Utf-8?B?cGF0cmlja2RyZA==?=, May 6, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    330
    MasterGaurav \(www.edujini-labs.com\)
    May 6, 2007
  5. jonjon
    Replies:
    0
    Views:
    208
    jonjon
    Oct 29, 2003
Loading...

Share This Page