Reputation: 315
Ok so I've got my Drop down list databound to an sql data source, now I need to change the data in a few of the fields before it gets displayed. I've been messing with this all morning and I can't find anything useful, this is what I've got so far and it's clearly not working...
Protected Sub ddlBookType_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBookType.DataBound
'ddlBookType.Items.Insert(0, "Any")
Dim i As Integer
For i = 0 To ddlBookType.Items.Count - 1
If ddlBookType.Items(i).Attributes.Equals("mod_cook") Then
ddlBookType.Items(i).Text.Replace("mod_cook", "Modern Cooking")
End If
Next
End Sub
Upvotes: 3
Views: 1911
Reputation: 72222
Hey I've just done it in C# and converted it into VB (I hope it's right).
Here's the code (
Protected Sub ddlBookType_DataBound(sender As Object, e As EventArgs)
Dim ddlBookType As DropDownList = DirectCast(sender, DropDownList)
For Each item As ListItem In ddlBookType.Items
If item.Text = "mod_cook" Then
item.Text = "Modern Cooking"
End If
Next
End Sub
And here's the original C# code
protected void ddlBookType_DataBound(object sender, EventArgs e)
{
DropDownList ddlBookType = (DropDownList)sender;
foreach (ListItem item in ddlBookType.Items)
{
if (item.Text == "mod_cook")
{
item.Text = "Modern Cooking";
}
}
}
Upvotes: 4