Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdownlist won't populate

Status
Not open for further replies.

spaulding

Technical User
Jan 10, 2001
123
US
I'd appreciate any help anyone can give with this. I'm building an administrative page which allows the user to insert URLs and text into a database making it easier for them to update their (separate) website. As part of this admin page, I've got a datagrid displaying their data. Since their website can have multiple pages, selected from a querystring, I need to update any changes to the database using the page identity (pageID), instead of the more user friendly pagename. I've been looking at this so long, I'm sure I'm missing something obvious, but I cannot get the dropdownlist to populate with anything. I've checked the SQL, there are 3 records that should be returned with that syntax. I would really appreciate another pair of eyes to look at the following code and let me know where I'm screwing it up. Thanks

Code:
<asp:datagrid id="dgLinks" runat="server" Width="100%" OnEditCommand="DgLinks_Edit" OnCancelCommand="dgLinks_Cancel"
OnUpdateCommand="dgLinks_Update" OnDeleteCommand="dgLinks_Delete"
DataKeyField="id" 
AutoGenerateColumns="False"
OnItemDataBound="dgLinks_Build">
<Columns>
							<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
								<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
							<asp:BoundColumn DataField="URL" HeaderText="URL"></asp:BoundColumn>
							<asp:TemplateColumn HeaderText="Displayed on">
								<ItemTemplate>
								<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PageName") %>'>
								</asp:Label>
								</ItemTemplate>
								<EditItemTemplate>
	<asp:DropDownList ID="ddlPages" Runat="server" DataValueField="pageid" DataTextField="PageName" DataSource="<%# GetPages() %>">
													</asp:DropDownList>
								</EditItemTemplate>
								</asp:TemplateColumn>
								<asp:BoundColumn DataField="LinkText" HeaderText="Link Text"></asp:BoundColumn>
								<asp:TemplateColumn HeaderText="Add'l Text">
								<ItemTemplate>
								<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Description") %>'>
								</asp:Label>
								</ItemTemplate>
								<EditItemTemplate>
													<asp:TextBox runat="server" id="addlText" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.Description") %>'>
													</asp:TextBox>
												</EditItemTemplate>
											</asp:TemplateColumn>
										</Columns>
									</asp:datagrid>


 Public ddlDataSet As DataSet = New DataSet

    Function GetPages() As DataSet

        Dim strsql As String = "Select PageID, PageName from DepartmentPage where DepartmentID=1"
        SqlConnection1.Open()
        Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(strsql, SqlConnection1)
        myDataAdapter.Fill(ddlDataSet, "Pages")
        SqlConnection1.Close()

        Return ddlDataSet

    End Function
 
did you put a breakpoint in GetPages() to see if it is being called?
 
Thanks for the help. Yes, the function is being called. I also dropped a throw-away datagrid on the page, set ddlDataset as it's datasource in the function and it populates exactly as expected. So, at least up to returning the dataset, things are working as expected.
 
try populating in OnItemDataBound="dgLinks_Build" to see if that makes a difference. i dont see why your code wouldnt work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top