Gridview question

Discussion in 'ASP .Net' started by Paul, Jun 10, 2008.

  1. Paul

    Paul Guest

    Hi I have a gridview with several template columns and a few command button
    columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column
    4 is a text box, followed by command button columns. These are all for data
    entry and although I am populating the dropdown list boxes with an
    objectdatasource so the user can provide a selection, I am not binding the
    gridview to anything. The command buttons again are for the user to be able
    to edit existing rows, delete and add new rows. The problem is that when the
    page first loads the gridview does not show up since I do not need to bind it
    to a datasource, although I am binding the two dropdown boxes to datasources.
    Just wondering if there is a way to make the grid visible when the page
    loads?
    --
    Paul G
    Software engineer.
    Paul, Jun 10, 2008
    #1
    1. Advertising

  2. Paul

    Manish Guest

    Hi Paul,

    You need to just assign the DataSource to the GridView control and add all
    the template columns and bind the controls in the ItemTemplate of the
    template columns to the Datasource and set the AutogenerateColumns property
    of the GridView to false.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server"
    AutoPostBack="True" DataSourceID="SqlDataSource1"
    DataTextField="CategoryID"
    DataValueField="CategoryID">
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:DropDownList ID="DropDownList2" runat="server"
    AutoPostBack="True" DataSourceID="SqlDataSource1"
    DataTextField="CategoryName"
    DataValueField="CategoryName">
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox ID="TextBox2"
    runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"
    ProviderName="<%$
    ConnectionStrings:NwindConnectionString.ProviderName %>"
    SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
    </asp:SqlDataSource>

    Hope this helps.

    Regards,
    Manish

    "Paul" wrote:

    > Hi I have a gridview with several template columns and a few command button
    > columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column
    > 4 is a text box, followed by command button columns. These are all for data
    > entry and although I am populating the dropdown list boxes with an
    > objectdatasource so the user can provide a selection, I am not binding the
    > gridview to anything. The command buttons again are for the user to be able
    > to edit existing rows, delete and add new rows. The problem is that when the
    > page first loads the gridview does not show up since I do not need to bind it
    > to a datasource, although I am binding the two dropdown boxes to datasources.
    > Just wondering if there is a way to make the grid visible when the page
    > loads?
    > --
    > Paul G
    > Software engineer.
    Manish, Jun 10, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    Hi, thanks for the response. So when the page loads I will need to assign a
    datasource to the gridview? If the datasource does not have any data in it
    will the grid still show up as when the page loads the dropdown boxes in the
    template columns will be the only thing prepopulated with data.
    --
    Paul G
    Software engineer.


    "Manish" wrote:

    > Hi Paul,
    >
    > You need to just assign the DataSource to the GridView control and add all
    > the template columns and bind the controls in the ItemTemplate of the
    > template columns to the Datasource and set the AutogenerateColumns property
    > of the GridView to false.
    >
    > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    > DataSourceID="SqlDataSource1">
    > <Columns>
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:DropDownList ID="DropDownList1" runat="server"
    > AutoPostBack="True" DataSourceID="SqlDataSource1"
    > DataTextField="CategoryID"
    > DataValueField="CategoryID">
    > </asp:DropDownList>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:DropDownList ID="DropDownList2" runat="server"
    > AutoPostBack="True" DataSourceID="SqlDataSource1"
    > DataTextField="CategoryName"
    > DataValueField="CategoryName">
    > </asp:DropDownList>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:TextBox ID="TextBox2"
    > runat="server"></asp:TextBox>
    > </ItemTemplate>
    > </asp:TemplateField>
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:CheckBox ID="CheckBox1" runat="server" />
    > </ItemTemplate>
    > </asp:TemplateField>
    > </Columns>
    > </asp:GridView>
    > </div>
    > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"
    > ProviderName="<%$
    > ConnectionStrings:NwindConnectionString.ProviderName %>"
    > SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
    > </asp:SqlDataSource>
    >
    > Hope this helps.
    >
    > Regards,
    > Manish
    >
    > "Paul" wrote:
    >
    > > Hi I have a gridview with several template columns and a few command button
    > > columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column
    > > 4 is a text box, followed by command button columns. These are all for data
    > > entry and although I am populating the dropdown list boxes with an
    > > objectdatasource so the user can provide a selection, I am not binding the
    > > gridview to anything. The command buttons again are for the user to be able
    > > to edit existing rows, delete and add new rows. The problem is that when the
    > > page first loads the gridview does not show up since I do not need to bind it
    > > to a datasource, although I am binding the two dropdown boxes to datasources.
    > > Just wondering if there is a way to make the grid visible when the page
    > > loads?
    > > --
    > > Paul G
    > > Software engineer.
    Paul, Jun 11, 2008
    #3
  4. Paul

    Manish Guest

    Hi Paul,

    Yes, you need to assign the datasource to gridview and set its
    Autogeneratecolumns property to false.

    Regards,
    Manish

    "Paul" wrote:

    > Hi, thanks for the response. So when the page loads I will need to assign a
    > datasource to the gridview? If the datasource does not have any data in it
    > will the grid still show up as when the page loads the dropdown boxes in the
    > template columns will be the only thing prepopulated with data.
    > --
    > Paul G
    > Software engineer.
    >
    >
    > "Manish" wrote:
    >
    > > Hi Paul,
    > >
    > > You need to just assign the DataSource to the GridView control and add all
    > > the template columns and bind the controls in the ItemTemplate of the
    > > template columns to the Datasource and set the AutogenerateColumns property
    > > of the GridView to false.
    > >
    > > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    > > DataSourceID="SqlDataSource1">
    > > <Columns>
    > > <asp:TemplateField>
    > > <ItemTemplate>
    > > <asp:DropDownList ID="DropDownList1" runat="server"
    > > AutoPostBack="True" DataSourceID="SqlDataSource1"
    > > DataTextField="CategoryID"
    > > DataValueField="CategoryID">
    > > </asp:DropDownList>
    > > </ItemTemplate>
    > > </asp:TemplateField>
    > > <asp:TemplateField>
    > > <ItemTemplate>
    > > <asp:DropDownList ID="DropDownList2" runat="server"
    > > AutoPostBack="True" DataSourceID="SqlDataSource1"
    > > DataTextField="CategoryName"
    > > DataValueField="CategoryName">
    > > </asp:DropDownList>
    > > </ItemTemplate>
    > > </asp:TemplateField>
    > > <asp:TemplateField>
    > > <ItemTemplate>
    > > <asp:TextBox ID="TextBox2"
    > > runat="server"></asp:TextBox>
    > > </ItemTemplate>
    > > </asp:TemplateField>
    > > <asp:TemplateField>
    > > <ItemTemplate>
    > > <asp:CheckBox ID="CheckBox1" runat="server" />
    > > </ItemTemplate>
    > > </asp:TemplateField>
    > > </Columns>
    > > </asp:GridView>
    > > </div>
    > > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    > > ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"
    > > ProviderName="<%$
    > > ConnectionStrings:NwindConnectionString.ProviderName %>"
    > > SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
    > > </asp:SqlDataSource>
    > >
    > > Hope this helps.
    > >
    > > Regards,
    > > Manish
    > >
    > > "Paul" wrote:
    > >
    > > > Hi I have a gridview with several template columns and a few command button
    > > > columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column
    > > > 4 is a text box, followed by command button columns. These are all for data
    > > > entry and although I am populating the dropdown list boxes with an
    > > > objectdatasource so the user can provide a selection, I am not binding the
    > > > gridview to anything. The command buttons again are for the user to be able
    > > > to edit existing rows, delete and add new rows. The problem is that when the
    > > > page first loads the gridview does not show up since I do not need to bind it
    > > > to a datasource, although I am binding the two dropdown boxes to datasources.
    > > > Just wondering if there is a way to make the grid visible when the page
    > > > loads?
    > > > --
    > > > Paul G
    > > > Software engineer.
    Manish, Jun 12, 2008
    #4
    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. Nalaka

    GridView in a GridView

    Nalaka, Nov 11, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    6,586
    Nalaka
    Dec 5, 2005
  2. Replies:
    3
    Views:
    5,091
  3. Carlos Albert

    GridView in a GridView

    Carlos Albert, Dec 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    484
    Carlos Albert
    Dec 6, 2005
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,940
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Cirene
    Replies:
    1
    Views:
    371
    gnewsgroup
    Nov 4, 2007
Loading...

Share This Page