making a server control visible / invisible in a DataList

S

SP

Hello there,

I have a DataList create as below.

<asp:DataList ID="dl_Immunpsuppressive_Main" Runat="server"
Width="100%">
<ItemTemplate>
<table id="Immunpsuppressive_Main" width="100%" border="0">
<tr>
<td class="sub" width="50%" colSpan="2">
<asp:Label ID="lbl_Imm_Main" Runat="server">
<%#((System.Data.DataRow)Container.DataItem)["MetaDataChoiceText"] %>
</asp:Label>
<asp:TextBox ID="txt_Imm_Main_Other" Runat="server" Width="150px"
Visible="False" ></asp:TextBox>
</td>
<td class="sub" width="5%" colSpan="1">
<asp:CheckBox ID="chk_Ind" Runat="server"></asp:CheckBox></td>
<td class="sub" width="19%" colSpan="1">
<asp:TextBox ID="txt_Days" Runat="server" Width="96px"></asp:TextBox>
</td>
<td class="sub" width="19%" colSpan="1">
<asp:DropDownList ID="ddl_ST" Runat="server"
Width="96px"></asp:DropDownList>
</td>
<td class="sub" width="5%" colSpan="1">
<asp:CheckBox ID="chk_Maint" Runat="server"></asp:CheckBox></td>
<td class="sub" width="5%" colSpan="1">
<asp:CheckBox ID="chk_AR" Runat="server"></asp:CheckBox></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

I need to make the TExtBox Control "txt_Imm_Main_Other" visible only
when it meets a particular condition:

I have the following code in my DataList ItemDataBound

TextBox txt_Imm_Main_Other =
(TextBox)e.Item.FindControl("txt_Imm_Main_Other");

if (txt_Imm_Main_Other != null)
{
MetaDataDAC metaDataDAC_Imm = new MetaDataDAC();
DataSet ds_Imm = metaDataDAC_Imm.Get(1, 2, null);

foreach(DataTable dt_Table in ds_Imm.Tables)
{
foreach (DataRow dr_Row in dt_Table.Rows)
{
if (dr_Row["MetaDataChoiceVal"].ToString() == "4")
{
txt_Imm_Main_Other.Visible = true;
txt_Imm_Main_Other.Enabled = true;
}
}
}

}

The TExtBox Control "txt_Imm_Main_Other" always is visible?

Please suggest!

Thanks,
Pai
 
S

SP

Hello All,

I got the answer, I was looping through a DataSet and trying to make
the control txt_Imm_Main_Other visible / invisible.

I changed the MetaDataDAC metaDataDAC_Imm = new MetaDataDAC();
DataSet ds_Imm = metaDataDAC_Imm.Get(1, 2, null);


foreach(DataTable dt_Table in ds_Imm.Tables)
{
foreach (DataRow dr_Row in dt_Table.Rows)
{
if (dr_Row["MetaDataChoiceVal"].ToString() == "4")
{
txt_Imm_Main_Other.Visible = true;
txt_Imm_Main_Other.Enabled = true;
}
}



}


to:

if (txt_Imm_Main_Other.Text == "5172")
{
txt_Imm_Main_Other.Text = "";
txt_Imm_Main_Other.Visible = true;
}
else
{
txt_Imm_Main_Other.Visible = false;
}

and it worked

Thanks,
Pai
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top