Solved

Dropdown in gridview ASP.NET,VB.NET

Posted on 2013-05-14
1
502 Views
Last Modified: 2013-05-15
I have a gridview in one of my aspx pages in which I want one column to be dropdown and one other to be a check box and rest to be text boxes. So when the gridview loads all the columns are read only but when the user hits edit button first column needs to be a dropdown with the the values in it being populated from a table in the database. second column needs to be checkbox. rest as textboxes.

Here is how I have created my gridview in the aspx.
<asp:GridView ID="GridView1" AutoGenerateColumns="true" AllowPaging="true" AllowSorting="true"  
            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
                runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
                Width="317px">
                <PagerSettings Position="Top" Mode="NumericFirstLast" />
                <PagerStyle HorizontalAlign="Right" VerticalAlign="Middle" BackColor="#ECF0FC" />
                <FooterStyle BackColor="#CCCCCC" />
                <HeaderStyle BackColor="#284E98" ForeColor="White" Font-Bold="True" />
                <EditRowStyle Wrap="False" />
                <AlternatingRowStyle BackColor="#F6F1D4" BorderColor="Black" />
            </asp:GridView>


Code Behind to populate the gridview:
 Dim cmdList As DbCommand = m_database.GetStoredProcCommand("storeproc_name")

Dim listDS As DataSet = m_database.ExecuteDataSet(cmdList)
            Dim iNoOfRowsReturend As Integer = listDS.Tables(0).Rows.Count
            ShowSearchMessage(iNoOfRowsReturend)

            GridView1.DataSource = listDS
            GridView1.DataBind()



Can someone please help me with this.

Thanks
0
Comment
Question by:pratikshahse
1 Comment
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39164596
Turn off auto generate columns.

For most of the fields you can get away with a bound column if you're just using the default textboxes.

For your field in question, you're going to want a template column with an itemtemplate that has a label and an edititemtemplate that has a dropdowlist.

Here is some sample code:
http://www.dotnetfunda.com/articles/article29.aspx
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now