Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to visible textbox and label based on the selection of dropdownlist value...


VB
<asp:Repeater ID="RepterDetails" runat="server"
       onitemcommand="RepterDetails_ItemCommand" >
 <ItemTemplate>

<pre> <tr>

    <td width="93" align="left" valign="middle">Marital Status</td>
    <td width="12" align="center" valign="middle">:</td>
        
    <td width="150" align="left" valign="middle"><asp:Label ID="lbl_marital" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "maritalstatus")%>' Font-Bold="true"></asp:Label>   
  
       <asp:DropDownList ID="marital" runat="server" class="feedback_textfield" Visible ="False" AppendDataBoundItems="true" OnSelectedIndexChanged="marital_SelectedIndexChanged"  AutoPostBack="true"  >
     <%--  <asp:ListItem>Select</asp:ListItem>--%>
     
       <asp:ListItem Value="1" >unmarried</asp:ListItem>
        <asp:ListItem Value="2">married</asp:ListItem></asp:DropDownList></td>   
        </tr>


based on the selection of dropdownlist value inside repeater,
i want to visible/invisible textboxes..

<asp:TextBox ID="txtwife" runat="server" class="feedback_textfield" Text='<%# Bind("wifename")%>'></asp:TextBox>


I have tried like this..


<pre>protected void ddlExtended_SelectedIndexChanged(object sender, EventArgs e)
        {
         DropDownList marital = (DropDownList)RepterDetails.FindControl("marital");

         TextBox txtwife = (TextBox)RepterDetails.FindControl("txtwife");
         if (marital.SelectedValue == "married")
            {
                txtwife.Visible = true;
            }
            else
            {
                txtwife.Visible = false;
            }
        }</pre>



While selecting Dropdown list value, I cant able to use the selected value..
Bcoz Its returning null Value..


Error:Object reference not set to an instance of an object.
its returning null value for



if (marital.SelectedValue == "married")


can anyone suggest me how to access dropdownlist selected value inside repeater..

Thanks in Advance
Posted
Updated 22-May-14 23:37pm
v2
Comments
Sunasara Imdadhusen 23-May-14 5:51am    
I have already given answer of your same question. Please do not post same question again and again.

1 solution

try finding the dropdown and textbox in ItemDataBound of your repeater


C#
protected void RepterDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
       e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DropDownList ddl = (DropDownList)e.Item.FindControl("marital");
        TextBox txt = (TextBox)e.Item.FindControl("txtwife");        
        // DO STUFF HERE !!!
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900