RadioButtonList in DataList EditItemTemplate

  • Thread starter Thread starter Sudheer Aalla
  • Start date Start date
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.
 
Back
Top