RadioButtonList in DataList EditItemTemplate

S

Sudheer Aalla

Hi,

When I try to reference the radiobuttonlist control in edititemtemplate in
ItemDataBound event of datalist control I am getting NULL reference. I am
trying to pre select the yes/no button depending on the label text in item
template. But I am able to get the value of lable control which is in
itemtemplate. Is there anything else I am missing here???

public void DataListItems_ItemDataBound(object sender, DataListItemEventArgs
e)

{

if (DataListItems.EditItemIndex != -1 && e.Item.ItemIndex != -1 &&
e.Item.HasControls())

{

Label rbllblIsAdded = (Label)e.Item.FindControl("lblIsAdded");

RadioButtonList rbl =
(RadioButtonList)e.Item.FindControl("edtrblIsAdded");

if (rbllblIsAdded.Text == "Added")

{

rbl.SelectedValue = "Yes";

}

else

{

rbl.SelectedValue = "No";

}

}

}



<EditItemTemplate>

<table width="100%" cellspacing="0" cellpadding="0" style="height:100%;">

<tr>

<td width="10%">

<asp:RadioButtonList ID="edtrblIsAdded" RepeatDirection="Horizontal"
runat="server">

<asp:ListItem Value="Yes">A</asp:ListItem>

<asp:ListItem Value="No">R</asp:ListItem>

</asp:RadioButtonList>

<asp:RequiredFieldValidator ID="RFVedtrblIsAdded" runat="server"
ErrorMessage="Please select added/removed"

ControlToValidate="edtrblIsAdded" ValidationGroup="UpdateValidationControls"
ToolTip="Please select added/removed">*</asp:RequiredFieldValidator>


</td>

........



Thanks,

Sudheer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top