Solved

Dropdown in gridview ASP.NET,VB.NET

Posted on 2013-05-14
1
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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