[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.net bound GridView and manually add a set of asp:BoundFields

Posted on 2014-01-06
2
Medium Priority
?
671 Views
Last Modified: 2014-01-06
In a bound ASP.net GridView how do you set AutoGenerateColumns to false and manually add a set of asp:BoundFields for your SQL columns rather than letting them be generated automatically.
0
Comment
Question by:Murray Brown
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39758981
Simplisticly it would be something like the following:
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <!-- These will be bound to fields in the data source -->
                <asp:BoundField DataField="Product_Name" />
                <asp:BoundField DataField="Description" />
                <!-- These are custom fields -->
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:RadioButtonList ID="Radio1" runat="server">
                            <asp:ListItem Value="1" Text="Yes" />
                            <asp:ListItem Value="0" Text="No" />
                        </asp:RadioButtonList>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Open in new window

Note the AutoGenerateColumns="false" in the definition of the GridView. The first two columns will bind to fields in you SQL Statement/data source, the TemplateField is independent of the data source.
0
 

Author Closing Comment

by:Murray Brown
ID: 39759034
Thanks very much. Appreciate it!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question