.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Gridview Dropdownlist Databind

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
Hi All, I am trying to Bind data dropdown list column only inside the gridview  while pageload using asp.net with c#.  I am able to bind the data to it but it is creating rows for total list itmes.  I want to bind to that at the first time i can able to see only one row. Later When i click on any one of the column then it will create a new row. Regards,

View Complete Post

More Related Resource Links

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

Accessing a row's dropdownlist values AFTER the gridview control is in Edit mode

Hello, I have a gridview control. When it goes into Edit mode, there are 3 dropdownlists in one cell that are populated by separate stored procedures during the RowDataBound event. The 1st dropdownlist's value is used as a parameter to determine what the 2nd dropdownlist is populated with. The 2nd dropdownlist's value is used as a parameter to determine what the 3rd dropdownlist is populated with. Everything works fine when the row is first put into Edit mode. While I'm in Edit mode and I change the selection in the 1st dropdownlist, how do I access the control so I can feed this new parameter to the 2nd dropdownlist? I have the first 2 dropdownlists set for AutoPostBack so that the Page_Load event is fired when the user changes a value. I know how to get access to these controls via the FindControl method when the row is being databound but how do I find the control during the Page_Load event? Thanks for any help!!!   Penny  

When to call DataBind on GridView?

So I have a GridView and several events that can be triggered (such as filtering and inserting a new record) to manipulate the GridView.  I want to make sure that I'm not calling DataBind on Page_Load, especially since I might have to call it again when certain events fire.  Is there a way I can make it so I only have to call DataBind once on the GridView after Page_Load and anything else has fired?  Like some event that will absolutely fire last where I can put my DataBind?  The reason I need to do this is because the DataSource for the GridView is set programmatically from a DataView when the page is loaded, so DataBind needs to run every time.  Just, hopefully, not multiple times each time...

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.I

Dropdownlist in gridview

hi all,here am posting my code.please solve my problem.problem was...when i trying to add new row in gridview(add button)the items in the dropdownlist was disappering...y it was happening? public partial class New_GeneralComplaints : System.Web.UI.Page { BalCallerTypeMaster bctm = new BalCallerTypeMaster(); BalComplaintMaster bcom = new BalComplaintMaster(); BalOriginMaster bom = new BalOriginMaster(); BalDestinationMaster bdsm = new BalDestinationMaster(); BalPriorityMaster bpm = new BalPriorityMaster(); BalStatus bs = new BalStatus(); BalArticle ba = new BalArticle(); DropDownList dpl1, dpl2, dpl3, dpl4, dpl5; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { SetInitialRow(); } /* // DropDownList dpl1 = (DropDownList)Gridview1.FindControl("Origin_Station"); DropDownList dpl2 = (DropDownList)Gridview1.FindControl("Delivery_Station"); DropDownList dpl3 = (DropDownList)Gridview1.FindControl("Article_Type");*/ if (!IsPostBack) { DataSet ds1 = bctm.getCallerTypeMaster(); Type_Caller.DataSource = ds1.Tables[0]; Type_Caller.DataTextField = ds1.Tables[0].Columns["Caller_Type_Desc"].ColumnName.ToString(); Type_Caller.DataValueField = ds1.Tables[0].Columns["Caller_Type_ID"].ColumnName.T

Gridview Dropdownlist

Hi, I want to display a dropdownlist inside one cell in my gridview when the user clicks edit. The user should then be able to select an option from the dropdownlist then click update and the selected option will be stored in the cell as text. The gridview is populated using a dataset which is created according to information selected by the user. During the row editing event I remove the textbox control from the cell then add the dropdownlist which is populated from a database table. This displays fine but the dropdown list then can't be found inside the row updating event. Here is a my code: Sub GridView_RowEditing event GridView.EditIndex = e.NewEditIndex   Dim ddl As New DropDownList ddl.ID = "DropDownList1" 'Populate dropdownlist from database GridView.Rows(GridView.EditIndex).Cells(7).Controls.RemoveAt(0) GridView.Rows(GridView.EditIndex).Cells(7).Controls.Add(ddl) End Sub Sub GridView_RowUpdating event Dim row As GridViewRow Dim row2 As DataRow row = CType(GridView.Rows(e.RowIndex), GridViewRow) 'I construct the new row (row2) here and try to find the dropdownlist to get something out of it but throws a null refference exception. row2(6) = CType(row.Cells(7).FindControl("DropDownList1"), DropDownList).Items(0).Text myDataSet.Tables(0).Rows(GridView.EditIndex).Delete() '

Problem Binding DropdownList in a gridView to a datasource

I have a Dropdownlist in an itemTemplate in a gridview. My gridView binds to dataTable1 (from which the selected value for dropdown comes from) and dropDown binds to dataTable2 (i need to get DataValueField and DataTextField from here).<asp:TemplateField HeaderText="Category"> <ItemTemplate> <asp:DropDownList ID="Cat" runat="server" SelectedValue='<%#Bind("CATEGORY") %>' > </asp:DropDownList> </ItemTemplate> <FooterStyle BorderStyle="None" /> <HeaderStyle BorderStyle="None" /> <ItemStyle BorderStyle="None" /> </asp:TemplateField>How do I do that? thanks in advance!

Validating DropdownList Inside Gridview Using Javascript

hi All,      I have Gridview with Dropdownlist which contains data as {select,1,2,3} .Gridview contains multiple rows of data.Submit button is also on form but outside gridview. If any of the rows of gridview dropdownlist contain value as "Select" and click Submit button ,give message as "Please select value". I want to do this stuff using javascript. Thanks in advance.

filter gridview from a dropdownlist with date

having trouble fing any info on what i need to be doing i have tried '{1}'  ,  '#{1}#' , '{1:MM/dd/yyyy}' and a whole bunch of combinations thereof Teh problem is when i get it to actual not have a complie error then the functionality is not correct as i am unable to "select" all from my dropdown list . The only way i have gotten anything close to working is by removinf the % from both the filter and the default value.   here is relevant code   <asp:DropDownList ID="ddlShipDate" AutoPostBack="true" runat="server" Height="16px" Width="75px" DataSourceID="adsPopulateShipDate" DataTextField="dShipDate" DataTextFormatString="{0:MM/dd/yyyy}" DataValueField="dShipDate"> <asp:ListItem Text="All" Value="%"></asp:ListItem> </asp:DropDownList> Pleas enote i removed the append databound items=true<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/JAGENT.mdb" SelectCommand="SELECT [cPronumber], [cCustomerRef], [dShipDate], [cOrigCity], [cOrigState], [dDeliveryDate], [cDestCity], [cDestState] FROM [BillingHistory] WHERE ([cCust

hoq to fill gridview dropdownlist from another db table

Hi, I have a gridview which gets its data from a database table now i ghave added a dropdownlist to this gridview but this dropdown should get the data from another table and should set its value automatically with a foreign key from the  gridview i have added the code like below in my rowDatabound but it just loads 1 field and then how should i get the selectedValue according to the gridview id field?? Protected Sub Friends_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)             If e.Row.RowType = DataControlRowType.DataRow Then                 Dim conn As New SqlConnection(HttpRuntime.Cache("con"))                Dim sql As String = "select ID,ListName from FriendList order by ListName asc"                Dim cmd As New SqlCommand(sql, conn)                cmd.CommandType = CommandType.Text                conn.Open()             &

Assign Value to DropDownList in GridView Dynamically

Hi, I got GridView with 2 columns both are Template field with drop down list. What I need to do is someting like when user select course 3/3A/2A/2B , the type column will auto select pratical option dynamically. When select RTT /FTT/BTT , the type column will select Theory option. Can someone tell me how to work on this thing. Thank you. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">  <Columns>  <asp:TemplateField HeaderText="Course">  <ItemTemplate>  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">  <asp:ListItem>2A</asp:ListItem>  <asp:ListItem>2B</asp:ListItem>  <asp:ListItem Value="3">3</asp:ListItem>  <asp:ListItem>3A</asp:ListItem>  <asp:ListItem>BTT</asp:ListItem>  <asp:ListItem>RTT</asp:ListItem>  <asp:ListItem>FTT</asp:ListItem>  <asp:ListItem></asp:ListItem>  </asp:DropDownList>  </ItemTemplate>  </asp:TemplateField>  <asp:TemplateField HeaderText="Type">  <ItemTemplate>  <asp:DropDownList ID="DropDownList2" runat="server">  <asp

dropdownlist in a gridview

can i use dropdownlist in a gridview

dropdownlist controls in gridview issue

 the below code creates drop down each time i add a category to the database table. however, i don't wish to have drop down created each time - how can i have all my data in one drop down? thanks...  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CascadingDropDownTestConnectionString %>"  SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category]">  </asp:SqlDataSource>    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"  DataSourceID="SqlDataSource1">  <Columns>  <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"  ReadOnly="True" SortExpression="CategoryID" />  <asp:TemplateField HeaderText="Categories">  <ItemTemplate>  <asp:DropDownList ID="ddlCategories" AutoPostBack="true" DataTextField="CategoryName"  DataValueField="CategoryID" DataSourceID="SqlDataSource1" runat="server" AppendDataBoundItems="true"  SelectedValue='<%# Bind("CategoryID") %>' />  &

Order of the items in a DropDownList inside GridView



I have a DropDownList inside the EditTemplateItem (if the user clicks edit) in a GridView. The DropDownList receives all available rows from the database.

My problem is, if the user clicks Edit in the GridView to edit a row and opens the DropDownList Box the original item is not selected but the first one. That means the items are sorted.

Have someone an idea how I can solve this issue that the right item / the original is selected if I change to edit mode of the grid view?

The only idear that I have is to write some lines in the code behind for the updating event and selected the suitable index manually but I think there must be an easier way.


Can't edit GridView columns after it's DataBind()


I have a gridview in my web application.  I use a SqlDataAdapter to fill a datatable, and then set my GridView's datasource as the datatable and do a DataBind() on the GridView.  But before I do the datasource selection and the databinding, I try to copy the first column and place it in the second column, and have an autoincrement in the first column ("1", "2", "3", etc.), but it the GridView is just blanked out then.  If I DON'T mess around with those columns then the GridView looks just normal like it should.

What could be going wrong with this???  My method is not working.  Any help is much appreciated.  Thanks in advance. :)

Gridview Dropdownlist databinding problem


I am using gridview, in ItemTemplate  I am using dropdownlist which has the hard-coded value, I want to get updated value of dropdownlist from database, but whenever I use EVAL, it throws the following error:

 'ddl' has a SelectedValue which is invalid because it does not exist in the list of items.

Parameter name: value

I am using the following code:

<asp:TemplateField HeaderText="Status"  >
                      <asp:DropDownList ID="ddl" runat="server" SelectedValue='<%# Bind("Status")%>' >

Add Dynamically TextBox And DropDownList In Gridview on Button Click Wich is placed outside of Gridv


Hi All,

   I have Gridview and Button Control on Form.i want to Add Dynamically TextBox And DropDownList In Gridview on Button Click Wich is placed outside of Gridview.

When i click on Button -> One TextBox and One Dropdownlist which contains values bydefault 1,2,3 should bind to gridview.    Button is placed outside Gridview.

Thanks in advance.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend