<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="country_code" EnableViewState="False" OnDataBound="FormView1_Databound">
<ItemTemplate>
<table style="width: 100%"><tr><td style="font-weight: bold; vertical-align: top; width: 170px; text-align: right">
<a href="member.aspx" class="type1">Member:</a></td>
<td valign="top" colspan="2">
<asp:FormView ID="FormView3" runat="server" DataSourceID="SqlDataSource4" Width="100%" OnDataBound="FormView3_DataBound" OnPreRender="FormView3_PreRender">
<ItemTemplate>
<table style="width: 100%" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 357px" valign="top">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</td>
<td style="width: 100px">
<asp:Image ID="Image5" runat="server" Height="90px" ImageUrl='<%# Eval("person_id", "http://amsweb.imf.org/countryinfo/getimagenodll.asp?personid={0}") %>'
Width="65px" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /></td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$
ConnectionStrings:BDVOTESConnectionString %>"
SelectCommand="selct distint a , b ,c from table where a.ccode = @cccode ">
<SelectParameters><asp:ControlParameter ControlID="FormView1" Name="ccode" PropertyName="SelectedValue" /></SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
The Code behind i tried is as but unable to find the literal and image control of child formview.Please advise:
The code i am using is like this but unable to find the literal and image control(they are null always but they should nt be null) :
Ist method :
protected void sqldatasource4_selected(object sender, SqlDataSourceStatusEventArgs e)
{
if(e.AffectedRows == 0)
{
FormView formView3 = FormView1.FindControl("FormView3") as FormView;
Literal ltrl = formView3.FindControl("Literal1") as Literal;
ltrl.Text = "No Records Found";
}
}
2nd Method :
protected void FormView3_DataBound(object sender, EventArgs e) //this manages missing institution display
{
FormView frm = (FormView)FormView1.FindControl("FormView3");
Literal lit = (Literal)frm.FindControl("Literal1");
Image IMFCImage = (Image)frm.FindControl("Image5");
DataRowView rowView = (DataRowView)frm.DataItem;
string badge_name = (rowView == null) ? "" : rowView["badge_name"].ToString();
string title_dept1 = (rowView == null) ? "" : rowView["title_dept1"].ToString();
string title_dept2 = (rowView == null) ? "" : rowView["title_dept2"].ToString();
string institution = (rowView == null) ? "" : rowView["institution"].ToString();
string countryNameFull = (rowView == null) ? "" : rowView["countryNameFull"].ToString();
if (badge_name == "vacant" || badge_name == "Vacant" || badge_name == "")
{
badge_name = "vacant";
if (lit != null)
{
lit.Text = badge_name;
IMFCImage.ImageUrl = "Images/no-view.jpg";
}
}
else
{
string strLit = badge_name + "<br />" + title_dept1 + title_dept2 + "<br />";
if (institution == "")
{
strLit += countryNameFull;
}
else
{
strLit += institution + "<br />" + countryNameFull;
}
if (lit != null)
{
lit.Text = strLit;
}
}
}