Advertisement

03.12.2008 at 08:40AM PDT, ID: 23235470
[x]
Attachment Details

How to change bound fields in Gridview dynamically

Asked by groovbox303 in .Net Editors & IDEs, .NET, Microsoft Development

Hi, I am new to using Object Data Source and am curious as far as its cusomizing limits. I would like to use the object Data Source in Gridview and am wondering the following things. I am using VB.NET in the code behind

1) Can the bound field names in the Gridview be changed at runtime / dynamically? for ex
<Columns>
        <asp:BoundField DataField="ProductName"
           HeaderText="ProductName" SortExpression="ProductName" />
        <asp:BoundField DataField="CategoryName" HeaderText="Category"
           ReadOnly="True"
</Columns>
Can I change the Bound field Data field in runtime since I am pulling data from different tables so the field names would be different, Is it possible to do this?

2) I want to do the same for a Dropdown template column. I want to be able to pull the lists of different types of products from different tables as well . Because from what I have seen If I use Edit Item Template and a seperate object Data source for the Drop down I have to assign the DataValue and text fields in the Data Source configuration Wizard.  Can I modify for e.g the following code in Code behind in VB.NET as well to give the label and the drop down different field names to bind to?

<asp:TemplateField HeaderText="Category" SortExpression="CategoryName">
    <EditItemTemplate>
        <asp:DropDownList ID="Categories" runat="server"
          DataSourceID="CategoriesDataSource"
          DataTextField="CategoryName" DataValueField="CategoryID">
        </asp:DropDownList>
        <asp:ObjectDataSource ID="CategoriesDataSource" runat="server"
            OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetCategories" TypeName="CategoriesBLL">
        </asp:ObjectDataSource>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server"
          Text='<%# Bind("CategoryName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

Thanks to anyone who can help me out with this. Please provide a sample of the code behind if this is possible. Your help's really appreciatedStart Free Trial
[+][-]03.12.2008 at 04:27PM PDT, ID: 21111860

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .Net Editors & IDEs, .NET, Microsoft Development
Sign Up Now!
Solution Provided By: RDdice
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.30.2008 at 01:04PM PDT, ID: 21241768

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.03.2008 at 04:18AM PDT, ID: 21699140

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.08.2008 at 07:04PM PDT, ID: 21740445

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628