Is it possible?

Results 1 to 2 of 2

Thread: Is it possible?

  1. #1
    Join Date
    Dec 1969

    Default Is it possible?

    Is it possible to reference a separate dropdownlist within a DataList? On a related note, is it possible to add a row at the top of a DataTable? If so, how? <BR><BR>I&#039;ve tried adding a dropdownlist within a DataList (distinct from the database information bound to the list) and was able to do so in the following manner:<BR><BR>&#060;asp:DropDownList id="ddlDonors" DataSource= &#039;&#060;%# LoadDonors()%&#062;&#039; DataTextField = "Name" DataValueField = "ID" SelectedIndex = &#039;&#060;%# Convert.ToInt32(DataBinder.Eval(Container.DataItem ,"ID"))%&#062;&#039; autoPostBack="true" onSelectedIndexChanged = "ddl_SelectedIndexChanged" runat="server"/&#062;<BR><BR>The dropdownlist displays correctly and fires the event handler appropriately, but I&#039;m then unable to determine the ddlDonor.SelectedItem.Value from the event handler. When I use the following code, I get an error indicating that &#039;ddlDonors&#039; couldn&#039;t be found:<BR><BR>void ddl_SelectedIndexChanged(Object sender, EventArgs e)<BR>{<BR>DisplayDonor(ddlDonors.SelectedIndex.Va lue);<BR>}<BR><BR>Is it possible to reference a separate dropdownlist within a DataList? If so, how? <BR><BR>On a related note, is it possible to add a row at the top of a DataTable? This is the LoadDonors() method that I&#039;m using to populate the ddlDonors above. I&#039;d like to have a blank selection at the top of the list, but have only succeeded in adding the row at the bottom.<BR><BR>protected DataSet LoadDonors()<BR>{ <BR>//Obtain Donor data for dropdown list<BR>DataSet dsDonors = new DataSet();<BR>string strSQL = "SELECT ID, Lname & &#039;, &#039; & [Fname] AS Name FROM tblPeople ORDER BY Lname";<BR>OleDbConnection objConnection = new OleDbConnection(ConfigurationSettings.AppSettings["strConnection"]);<BR>OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL, objConnection);<BR>objAdapter.Fill(dsDonors, "Donors");<BR>DataTable objTable = dsDonors.Tables["Donors"];<BR>DataRow objNewRow = objTable.NewRow();<BR>objNewRow["Name"] = "";<BR>objTable.Rows.Add(objNewRow);<BR>return dsDonors;<BR>}<BR><BR>Thanks in advance for any guidance on this!<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Is it possible?

    Not sure where and when you are wanted to reference this seprate drop down list. But let me pretend you want to do it off of a button click in the same row as your drop down list. I dont know C# so you will have to translate this VB<BR><BR>sub FindDropDown(sender as object, e as eventArgs)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Dim tempDropDown as dropDown = sender.Parent.FindControl("theNameOfYourDropDown") <BR>end sub<BR><BR>This is sort of a complex way for your second problem but you could add a column to your dataset which has a counter starting at 1 which is auto incremented then insert a record at the end with a 0 in this column then sort by that column.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts