I need to visible textbox and label based on the selection of dropdownlist value...
<asp:Repeater ID="RepterDetails" runat="server"
onitemcommand="RepterDetails_ItemCommand">
<ItemTemplate>
<asp:DropDownList ID="marital" runat="server" class="feedback_textfield" AutoPostBack="true" OnSelectedIndexChanged="ddlExtended_SelectedIndexChanged">
<%-- <asp:ListItem>Select</asp:ListItem>--%>
<asp:ListItem>unmarried</asp:ListItem>
<asp:ListItem>married</asp:ListItem></asp:DropDownList>
based on the selection of dropdownlist value inside repeater,
i want to visible/invisible textboxes..
<td width="93" align="left" valign="middle"><asp:Label ID="lblwife" runat="server" Text="Wife Name" ></asp:Label></td>
<td width="12" align="center" valign="middle"><asp:Label ID="Label2" runat="server" Text=":" ></asp:Label></td>
<td width="150" align="left" valign="middle"><asp:Label ID="lbl_wife" runat="server" Text='<%# Bind("wifename")%>' Font-Bold="true"></asp:Label>
<asp:TextBox ID="txtwife" runat="server" class="feedback_textfield" Text='<%# Bind("wifename")%>' Visible="false"></asp:TextBox></td>
</tr>
I have tried like this..
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;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
SqlConnection SqlCnn = new SqlConnection(s1);
SqlCommand SqlCmd = new SqlCommand("select * from registration", SqlCnn);
SqlDataAdapter SqlAd1 = new SqlDataAdapter(SqlCmd);
DataSet ds = new DataSet();
SqlAd1.Fill(ds, "registration");
RepterDetails.DataSource = ds;
RepterDetails.DataBind();
}
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.
if (marital.SelectedValue == "married")
..
can anyone suggest me how to access dropdownlist selected value inside repeater..
Thanks in Advance