Gridview question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGF1bA==?=

    Gridview question

    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
    objectdatasourc e 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.
  • =?Utf-8?B?TWFuaXNo?=

    #2
    RE: Gridview question

    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 AutogenerateCol umns property
    of the GridView to false.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
    DataSourceID="S qlDataSource1">
    <Columns>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:DropDownLi st ID="DropDownLis t1" runat="server"
    AutoPostBack="T rue" DataSourceID="S qlDataSource1"
    DataTextField=" CategoryID"
    DataValueField= "CategoryID ">
    </asp:DropDownLis t>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:DropDownLi st ID="DropDownLis t2" runat="server"
    AutoPostBack="T rue" DataSourceID="S qlDataSource1"
    DataTextField=" CategoryName"
    DataValueField= "CategoryNa me">
    </asp:DropDownLis t>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:TextBox ID="TextBox2"
    runat="server"> </asp:TextBox>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:CheckBox ID="CheckBox1" runat="server" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    </div>
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:NwindConnect ionString %>"
    ProviderName="< %$
    ConnectionStrin gs:NwindConnect ionString.Provi derName %>"
    SelectCommand=" SELECT [CategoryID], [CategoryName] FROM [Categories]">
    </asp:SqlDataSour ce>

    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
    objectdatasourc e 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.

    Comment

    • =?Utf-8?B?UGF1bA==?=

      #3
      RE: Gridview question

      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 AutogenerateCol umns property
      of the GridView to false.
      >
      <asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
      DataSourceID="S qlDataSource1">
      <Columns>
      <asp:TemplateFi eld>
      <ItemTemplate >
      <asp:DropDownLi st ID="DropDownLis t1" runat="server"
      AutoPostBack="T rue" DataSourceID="S qlDataSource1"
      DataTextField=" CategoryID"
      DataValueField= "CategoryID ">
      </asp:DropDownLis t>
      </ItemTemplate>
      </asp:TemplateFie ld>
      <asp:TemplateFi eld>
      <ItemTemplate >
      <asp:DropDownLi st ID="DropDownLis t2" runat="server"
      AutoPostBack="T rue" DataSourceID="S qlDataSource1"
      DataTextField=" CategoryName"
      DataValueField= "CategoryNa me">
      </asp:DropDownLis t>
      </ItemTemplate>
      </asp:TemplateFie ld>
      <asp:TemplateFi eld>
      <ItemTemplate >
      <asp:TextBox ID="TextBox2"
      runat="server"> </asp:TextBox>
      </ItemTemplate>
      </asp:TemplateFie ld>
      <asp:TemplateFi eld>
      <ItemTemplate >
      <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
      </asp:TemplateFie ld>
      </Columns>
      </asp:GridView>
      </div>
      <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      ConnectionStrin g="<%$ ConnectionStrin gs:NwindConnect ionString %>"
      ProviderName="< %$
      ConnectionStrin gs:NwindConnect ionString.Provi derName %>"
      SelectCommand=" SELECT [CategoryID], [CategoryName] FROM [Categories]">
      </asp:SqlDataSour ce>
      >
      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
      objectdatasourc e 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.

      Comment

      • =?Utf-8?B?TWFuaXNo?=

        #4
        RE: Gridview question

        Hi Paul,

        Yes, you need to assign the datasource to gridview and set its
        Autogeneratecol umns 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 AutogenerateCol umns property
        of the GridView to false.

        <asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
        DataSourceID="S qlDataSource1">
        <Columns>
        <asp:TemplateFi eld>
        <ItemTemplate >
        <asp:DropDownLi st ID="DropDownLis t1" runat="server"
        AutoPostBack="T rue" DataSourceID="S qlDataSource1"
        DataTextField=" CategoryID"
        DataValueField= "CategoryID ">
        </asp:DropDownLis t>
        </ItemTemplate>
        </asp:TemplateFie ld>
        <asp:TemplateFi eld>
        <ItemTemplate >
        <asp:DropDownLi st ID="DropDownLis t2" runat="server"
        AutoPostBack="T rue" DataSourceID="S qlDataSource1"
        DataTextField=" CategoryName"
        DataValueField= "CategoryNa me">
        </asp:DropDownLis t>
        </ItemTemplate>
        </asp:TemplateFie ld>
        <asp:TemplateFi eld>
        <ItemTemplate >
        <asp:TextBox ID="TextBox2"
        runat="server"> </asp:TextBox>
        </ItemTemplate>
        </asp:TemplateFie ld>
        <asp:TemplateFi eld>
        <ItemTemplate >
        <asp:CheckBox ID="CheckBox1" runat="server" />
        </ItemTemplate>
        </asp:TemplateFie ld>
        </Columns>
        </asp:GridView>
        </div>
        <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
        ConnectionStrin g="<%$ ConnectionStrin gs:NwindConnect ionString %>"
        ProviderName="< %$
        ConnectionStrin gs:NwindConnect ionString.Provi derName %>"
        SelectCommand=" SELECT [CategoryID], [CategoryName] FROM [Categories]">
        </asp:SqlDataSour ce>

        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
        objectdatasourc e 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.

        Comment

        Working...