Hi All,
I want to diaply or Hide Repeater column depend on the repeater item value. here is my code.
<asp:Repeater
ID="rptSearchResults"
runat="server"
DataSourceID="xmlSearchResults"
OnItemDataBound="rptSearchResults_OnItemDataBound"
EnableViewState="false">
<HeaderTemplate><thead> <th <th <th <th <th <th <th <th <th <th tr> thead> HeaderTemplate><ItemTemplate> <tr <td <asp:HiddenField td> <td><asp:LinkButton <td><%# <td><%# <td><%# <td><%# <td><%# <td><%# <td><%# <td><%# tr> ItemTemplate>asp:Repeater> In code behind if I have data in protected { HiddenField if { TierIndicator.Visible =true; HtmlTableCell } if { HtmlTableCell if TierIndicator.Visible =true; tImage.Alt =""; tdTierImage.Controls.Add(tImage); } } { tdTierImage.Visible =false; tImage.ID =Guid.NewGuid().ToString().Substring(0, tImage.Alt =""; tdTierImage.Controls.Add(tImage); } } } }return; } return; In the above code if I have data in Item template then I need to dispaly Image in the Item and same time need to display the Preferred Thanks, Sureya Ok, here you need to take a look from a little bit different angle of vision. There is model that you retrieved from database and you bind it to UI in order to display model's data in some special way. The UI may be changed as much as needed, i.e. replaced
id="PFacility"
runat
="server"
visible="false"
align="middle">Preferred<br/>Facility?th>
align="middle">ETIN/NPIth>
align="middle">Provider
Nameth>
align="middle">Addressth>
align="middle">Cityth>
align="middle">Stateth>
align="middle">ZIP
Codeth>
align="middle">Countyth>
align="middle">Phone
Numberth>
align="middle">Specialtyth>
<%#
RenderTableRowOnClick(Container) %> <%#
!IsRowSelectable(Container) ? "class=\"Inactive\"" : "" %>>
id="Image"
runat
="server"
visible="false"
align
="center">
Value='<%#
XPath("./NetworkCode")%>'
ID="hiddenNetworkCode"
runat="server"
/>
ID="lnkDetail"
CssClass="RowSelector"
runat="server">asp:LinkButton><%#
FormattedEtinOrNpi(Container)%>td>
FormattedName(Container)%>td>
FormattedStreetAddress(Container)%>td>
XPath("./ContactInformation/City")%>td>
XPath("./ContactInformation/State")%>td>
XPath("./ContactInformation/ZipCode")%>td>
XPath("./ContactInformation/County")%>td>
FormattedPhone(Container)%>td>
XPath("./Specialty")%>td>
<asp:HiddenField
Value='<%#
XPath("./NetworkCode")%>'
ID="hiddenNetworkCode"
runat="server"
/>
value I need to display the Column i.e.
<asp:HiddenField
Value='<%#
XPath("./NetworkCode")%>'
ID="hiddenNetworkCode"
runat="server"
/>.
How can I achive this in my code behind. Below is my code behind in .aspx.cs page
void
rptSearchResults_OnItemDataBound(object
sender, RepeaterItemEventArgs
e)
hiddenEtin = e.Item.FindControl("hiddenNetworkCode")
as
HiddenField;
(e.Item.ItemType == ListItemType.Header
&& hdnHeader.Value.Contains("ADVN")
&& WorkflowState.StateData.SearchParameters.ProviderType.Value =="Facility")
thTierFacility = (HtmlTableCell)e.Item.FindControl("PFacility");
if (thTierFacility !=
null)
{ thTierFacility.Visible =true;
}
(hiddenEtin != null)
string strNetworkCode = hiddenEtin.Value;
if ((e.Item.ItemType ==
ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
&& WorkflowState.StateData.SearchParameters.ProviderType.Value =="Facility")
{
tdTierImage = (HtmlTableCell)e.Item.FindControl("Image");
(!string.IsNullOrEmpty(strNetworkCode)
&& strNetworkCode.Contains("ADVN"))
{
HtmlTableCell thTierFacility = (HtmlTableCell)e.Item.FindControl("PFacility");
if (thTierFacility !=
null)
{ thTierFacility.Visible =true;
}
if (tdTierImage !=
null)
{ tdTierImage.Visible =true;
HtmlImage tImage =
new
HtmlImage();
tImage.ID =Guid.NewGuid().ToString().Substring(0,
6);
else {if
(tdTierImage != null)
6);
tImage.Src ="";
}
<br/>Facility?
Column Header.
by GridView or splitted up to several controls, hence you should not rely on it. This means you do not need to search for hidden controls (markup-specific things) in item template, rather than that use the data in your model:protected void outerRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
//extract NetworkCode value from underlying model
IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
XPathNavigator nav = x.CreateNavigator();
XmlElement root = (XmlElement)nav.UnderlyingObject;
string networkCode = root.SelectSingleNode("NetworkCode").InnerText;
//hide/display the column in header
var isVisible = networkCode.ToUpper().Contains("ADVN");
var column = e.Item.FindControl("PFacility") as Control;
if (column != null)
{
column.Visible = isVisible;
}
}
}
沒有留言:
張貼留言