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

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

dropdownlist selected value within gridview

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

hi frens,

i've a GridView1, inside that i've a <TemplateField> within the <EditItemTemplate> i've a drop down list like


<asp:DropDownList ID="ddlArtistsinSrcSongsEdit" DataSourceID="srcSongsfromArtists" DataTextField="fname" DataValueField="Artistid" runat="server"  />

who's sqldatasource is 

 <asp:SqlDataSource ID="srcSongsfromArtists" runat="server" ConnectionString="<%$ ConnectionStrings:Albums %>"         SelectCommand="select artistid, fname from artists">


coz, in the editing mode i want the end user to select any of the artists available i wrote the above (SelectCommand) select artistid, fname from artists

but when the GridView1 is in the editing mode, it obviously displays the first artist, i want to display the actual drop down value that was available before the GridView1 went into the Editing mode, pls help, thanks in advance


View Complete Post

More Related Resource Links

gridview dropdownlist selected indeex change event



I bind the ddl as name column in gridview and age as textbox in the next column.

 void bind()


 SqlCommand com = new SqlCommand("Select id,name from employee", con);

SqlDataAdapter da = new SqlDataAdapter(com);

DataSet ds = new DataSet();


GridView1.DataSource = ds;


SqlDataAdapter da1 = new SqlDataAdapter("select id,name from employee", con);

DataSet ds1 = new DataSet();


for (int i = 0; i < GridView1.Rows.Count; i++)


 DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("ddlname");

ddl.DataTextField = "Name";

 ddl.DataValueField = "Id";

ddl .DataSource = ds;




the above coding i fallow but in selelected indexchange event i have to dispaly the age of particular name in gridview.

Gridview that exports selected rows to Excel

his seems like a messy workaround, but I ended up using two Gridviews - one to display my data and show my checkboxes, and the other which was invisible amd would eventually end up as my Excel spreadsheet.

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.

How to let user edit selected gridview columns, not entire row



I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?


Rendering data with HTML tags in the DD Gridview for a selected column


I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                // Html Encode the cells


but this event never fires?

Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!

how can i display the selected value of dropdownlist from edittemplate to label from itemtemplate?


I have a detailsview with a dropdownlist in it. the detailsview is connected to a database table(employees having the following fields: id-smallint,name-nvarchar, departmnet-smallint). the ddl is connected to another table (departments with the following fields: id-smallint, departmentName-nvarchar). the ddl is in the edititemTempalte of the department field. My goal is to display in  the itemtemplate the departmentName (the selected value from the edititemtemplate ). How can I do this? Doyou have any ideas?

thanks a lot

dropdownlist - default value is not 'selected value'

i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manually selected value, so the label control never displays a null value?

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  

Gridview Selected Value is Not a Primary Key

Hello,  I have 2 GridViews.  One is working perfectly.  What I would like to have happen is when a row is selected on GridView1 (with Primary key of OrderNumber), the matching records from the field in GridView1 ClientID to show up in GridView2. <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="\\sjfileserver\data\database\S.J. Rollins Technologies Information Center.mdb" SelectCommand="SELECT [ClientID], [OrderNumber], [Field1] FROM [ORDERS] WHERE ([ClientID] = ?)"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="ClientID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:AccessDataSource> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="AccessDataSource2"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="ClientID" SortExpression="ClientID" /> <asp:BoundField DataField="OrderNumber" HeaderText="OrderNumber"

Selected Value in Gridview not Accessable via SelectedIndex

I'm trying to keep these questions seperate for people searching after me, so sorry if there is so many.I have the following code on SelectedIndexChange of GridView1HFCustomerID.Value = GridView1.Rows(GridView1.SelectedIndex).Cells(6).Text.ToString()I have a drop down list that you can choose values from, and depending on which item you pick GridView1 changes, this all works correctly, and if I select one of the rows the SelectedIndex changes.  My problem occurs when you choose a different value from the drop down list, GridView1 Changes accordingly, and by default a record is selected.  But selectedindexchange is never fired again until I manually select another record from the gridview which is a problem.Any Ideas?  Am I putting this code in the incorrect place?

ASP.Net MVC Dropdownlist and selected value problem

I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea. Controller Code public ActionResult Edit(int i) {      var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");      ViewData["MST_COUNTRies"] = items; } View Code <p>     <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%> </P>I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea.Controller Codepublic ActionResult Edit(int i){     var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");     ViewData["MST_COUNTRies"] = items;}View Code<p>    <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%></P>

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 Databind

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,

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() '

Get selected row value based on checkbox selected in gridview using jquery

Hi ,    i am having gridview with two columns.one column contains checkboxes and another column contains Name.i have given UserId to DataKeyNames in gridview.Now i will check some checkboxes in gridview and click on button GetData. whenver i click on button GetData i need to get datakey values of all the gridview rows whatever checked in gridview using JQUERYPlease help me i am new to JQUery

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!

Fill a Listbox with value selected from a Dropdownlist

Hi, Maybe the question has already be posted, but I didn't find it.I have in my web page two controls: a dropdownlist and a listboxMy goal is to fill the listbox with values from my database depending on what I have selected in my dropdownlist.I wouldlike to use the CascadingDropDown component for that. Is that possible ??(I tried on my own and I get this error messageException Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.ListBox' to type 'System.Web.UI.WebControls.DropDownList'.I think it's when i tried to fill the listbox with this function:[WebMethod] public CascadingDropDownNameValue[] GetAppliForDomain(string knownCategoryValues, string category) { int domainID; //this stringdictionary contains has table with key value pair of country and countryID StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!kv.ContainsKey("Domain") || !Int32.TryParse(kv["Domain"], out domainID)) { throw new ArgumentException("Couldn't find Domain."); }; SqlConnection con = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text
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