Gridview question

P

Paul

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?
 
M

Manish

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
 
P

Paul

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 said:
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 said:
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?
 
M

Manish

Hi Paul,

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

Regards,
Manish

Paul said:
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 said:
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 said:
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?
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top