开发者

Can't set value of hidden input to comma seperated list in ASP VB.net

开发者 https://www.devze.com 2023-04-10 06:39 出处:网络
Hi I\'ve run into a really annoying problem, I\'m trying to set the value of a hidden input to a comma seperated list taken from a database but in pure CSV format it won\'t set the value.

Hi I've run into a really annoying problem, I'm trying to set the value of a hidden input to a comma seperated list taken from a database but in pure CSV format it won't set the value.

The input tag and ul tag looks like this (I am aware of asp:hiddenfield and it's value property but I'm not using it as I still have this issue):

<ul id="keywords" runat="server">
</ul>
<input type="hidden" id="keywordsBox" runat="server" />

The code I'm using to populate it is:

'connection strings and all that stuff is set up and using a SqlDataReader to sort through results
while result.Read()
    keywordsBox.Attribute.Add("value", result.Item("keywords"))
    keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",开发者_Go百科","</li><li>") & "</li>"
End while

This will populate the li tags but will not populate the value for the input, I've tried using the replace function on the list for the value but it only works if I remove the commas or put other characters infront of them. I've also tried replacing it with the HTML code for a comma but just prints the HTML code out.

Has anybody else ran into this at all? How'd you fix it?


Try the below code, this will solve your problem:

dim hValue as string =""
while result.Read()
    hValue += result.Item("keywords")
    keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",","</li><li>") & "</li>"
End while
keywordsBox.Attribute.Add("value", hValue )
0

精彩评论

暂无评论...
验证码 换一张
取 消