Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview question

Reply
Thread Tools

Gridview question

 
 
Paul
Guest
Posts: n/a
 
      06-09-2008
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.
 
Reply With Quote
 
 
 
 
Manish
Guest
Posts: n/a
 
      06-10-2008
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>
<aspropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="CategoryID"
DataValueField="CategoryID">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<aspropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="CategoryName"
DataValueField="CategoryName">
</aspropDownList>
</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.ProviderNa me %>"
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.

 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      06-11-2008
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>
> <aspropDownList ID="DropDownList1" runat="server"
> AutoPostBack="True" DataSourceID="SqlDataSource1"
> DataTextField="CategoryID"
> DataValueField="CategoryID">
> </aspropDownList>
> </ItemTemplate>
> </asp:TemplateField>
> <asp:TemplateField>
> <ItemTemplate>
> <aspropDownList ID="DropDownList2" runat="server"
> AutoPostBack="True" DataSourceID="SqlDataSource1"
> DataTextField="CategoryName"
> DataValueField="CategoryName">
> </aspropDownList>
> </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.ProviderNa me %>"
> 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.

 
Reply With Quote
 
Manish
Guest
Posts: n/a
 
      06-12-2008
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>
> > <aspropDownList ID="DropDownList1" runat="server"
> > AutoPostBack="True" DataSourceID="SqlDataSource1"
> > DataTextField="CategoryID"
> > DataValueField="CategoryID">
> > </aspropDownList>
> > </ItemTemplate>
> > </asp:TemplateField>
> > <asp:TemplateField>
> > <ItemTemplate>
> > <aspropDownList ID="DropDownList2" runat="server"
> > AutoPostBack="True" DataSourceID="SqlDataSource1"
> > DataTextField="CategoryName"
> > DataValueField="CategoryName">
> > </aspropDownList>
> > </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.ProviderNa me %>"
> > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question: Gridview within Gridview issue Cirene ASP .Net 1 11-04-2007 05:38 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
GridView in a GridView Carlos Albert ASP .Net 2 12-06-2005 12:42 PM
GridView in a GridView Nalaka ASP .Net 6 12-05-2005 05:48 PM
Gridview with combobox whose data is dependent on field in gridview wallermj@hotmail.com ASP .Net 3 11-21-2005 05:34 PM



Advertisments