我建立了一个.aspx
包含下拉菜单的模板(没有.asp控件)。
范本范例:
<select>
<option selected="selected" value="">Bitte wählen</option>
<asp:Repeater ID="countryDropDown" runat="server">
<HeaderTemplate>
<option value="<%--key--%>">
</HeaderTemplate>
<ItemTemplate>
<%--value--%>
</ItemTemplate>
<FooterTemplate>
</option>
</FooterTemplate>
</asp:Repeater>
</select>
此下拉列表应包含所有国家/地区。所有国家/地区都存储在Kentico特定Custom.resex
的CMSResoures
文件夹中。
现在,我想遍历文件并将国家列表传递给转发器。我无法为此找到解决方案。
当然,使用KenticoResHelper.GetString("stringKey")
函数通过键获取特定值很容易,但是找不到使用Kentico库接收所有条目的方法。
如果您想以超级简单的方式执行此操作,则只需注册在〜/ CMSFormControls / CountrySelector.ascx中找到的“国家/地区选择器”,如下所示:
它具有与您正在处理的功能相同的功能。
但是,为了将来参考,所有国家/地区已经存储在数据库的CMS_Countries表中。用所有国家/地区填充数据集,然后将数据集分配为转发器的数据源会容易得多。这是执行此操作的众多方法之一:
//Set the connection string to the Kentico Database in the web.config to a variable called CMSConnectionString
string CMSConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString;
//Sets the text of the query we want to execute on the database to a variable called queryText
string queryText = "SELECT * FROM dbo.CMS_Countries";
//Creates a new instance of the SqlDataAdapter object and calls it "adapter".
//We pass in the text of the query we want to executre on the Kentico database, and the connetion string to the Kentico database.
SqlDataAdapter adapter = new SqlDataAdapter(queryText, CMSConnectionString);
//Creates a new instance of the DataSet object and calls it "countries".
DataSet countries = new DataSet();
//Fills the "countries" dataset with the data retrieved by our query on the Kentico database.
adapter.Fill(countries);
//Sets the datasource of the repeater to the dataset that we just created.
repeater.DataSource = countries;
//Binds the datasource to the repeater server control
repeater.DataBind();
最后,如果您绝对必须使用CMS.resx文件,则应签出。如何用XML填充数据表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句