我可以使用ASPTokkenInput轻松创建标签,并以字符串的形式保存在数据库中。
例如:我创建了3个标签,例如JAVA C# Entity
并将这些标记保存在java,c#,entity
但是在从数据库中使用sql查询获取后,我需要在ASPTokenInput中以TAGS的形式创建此字符串。
如何在C#中创建.cs页面的标签?
以下是创建代码的代码 ASPX页面
<ati:ASPTokenInput ID="StateNameBox" runat="server"
RequestHandlerPath="SearchItemList.aspx?type=StateName"
OnListChanged="StateName_ListChanged" Theme="facebook"
PostbackOnItemAdded="True" PostbackOnItemRemoved="True"
HintText="Start Typing StateName..." PreventDuplicates="True"/>
<asp:ListBox ID="StateNameList" runat="server" Width="100%" Height="150px"
style="display:none;" />
.csPage
protected void StateName_ListChanged(object sender, ASPTokenInput.ListChangedEventArgs e)
{
if (e.Action == ASPTokenInput.ListChangeActions.Add)
StateNameList.Items.Add(e.Item.name);
else
{
for (int n = StateNameList.Items.Count - 1; n >= 0; --n)
{
string removelistitem = e.Item.name;
if (StateNameList.Items[n].ToString().Contains(removelistitem))
{
StateNameList.Items.RemoveAt(n);
}
}
}
}
按钮点击以保存在数据库中
String state = "";
for (int j = 0; j < StateNameList.Items.Count; j++)
{
state = (StateNameList.Items[j].Text)+","+state;
}
将状态字符串保存到数据库
现在,我从数据库中获取此字符串,需要在ASPTokenInput
中创建标记 conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
objsqlconn = new SqlConnection(conn);
objsqlconn.Open();
objcmd = new SqlCommand("Select state from StateName where stateId='1'");
sqlread = objcmd.ExecuteReader();
String statename = "";
if (sqlread.Read())
{
statename = sqlread.GetString(0);
}
String[] statelist = statename.Split(',');
for(int i=0;i<statelist.Length;i++){
//now here what i want to do for createing tags again in ASPTokenInput
}