Adding Attributes to a ListItem

Results 1 to 2 of 2

Thread: Adding Attributes to a ListItem

  1. #1
    Join Date
    Dec 1969

    Default Adding Attributes to a ListItem

    Hey - I am pretty new with dotNet so maybe I am pulling a bonehead but here is my problem.<BR><BR>I have a RadioButtonList inside of a DataGrid. When I am DataBinding the RadioButtonList I am attempting to set the onClick attribute of each item in the RadioButtonList. I have come to realize that the ListItem.Attributes is just a get. So how do I do it??????<BR><BR>Here is a sample of what I am trying to do:<BR><BR><BR>[code language="C#"]<BR>public void OnDataBinding(object sender, EventArgs e)<BR> {<BR> RadioButtonList myRBList = (RadioButtonList) sender;<BR> DataGridItem container = (DataGridItem) myRBList.NamingContainer;<BR> <BR> ListItem LiDisplay = myRBList.Items.FindByValue("D");<BR> LiDisplay.Selected= true;<BR> LiDisplay.Value = ((DataRowView)container.DataItem)[colname].ToString();;<BR> LiDisplay.Attributes["onClick"] = "addOrRemoveItemToDisplay(&#039;" + ((DataRowView)container.DataItem)[colname].ToString() + "&#039;, &#039;" + ((DataRowView)container.DataItem)[colname].ToString() +"&#039;, &#039;D&#039;)";<BR> <BR> ListItem LiExclude = myRBList.Items.FindByValue("E");<BR> LiExclude.Value = ((DataRowView)container.DataItem)[colname].ToString();<BR> LiExclude.Attributes["onClick"] = "addOrRemoveItemToDisplay(&#039;" + ((DataRowView)container.DataItem)[colname].ToString() + "&#039;, &#039;" + ((DataRowView)container.DataItem)[colname].ToString() +"&#039;, &#039;E&#039;)";<BR> }[/code]<BR><BR>Thanks in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: Adding Attributes to a ListItem

    It&#039;s only read-only the way you&#039;re accessing it :)<BR><BR>LiDisplay.Attributes.Add(....) is what you want

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts