Hi
Into my application there is a panel inside a panel inside a formview its look like below, what i am facing is the error message : " Object reference not set to an instance of an object." next to line: " if (ShwUpSocids.Tables[0].Rows.Count > 0) ". as i want the updatesocialpanel to be shown in case if the UsrType = 'Business';. Now if i use DataBound for the listview then i will not be able to bind when page is load as i think if i am mistaken please could explain how i can do it?
<asp:Panel ID="EditUsrPan" runat="server">
<asp:FormView ID="EditUsrInfoFVw" runat="server">
<ItemTemplate>
<asp:Panel ID="updatesocialpanel" runat="server">
</asp:Panel>
</ItemTemplate>
</asp:FormView>
</asp:Panel>
Below code is to show the updatesocialpanel in case if user are business
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UsrNme"] != null)
{
using (SqlConnection ShwUpSociCon = new SqlConnection(sc))
{
ShwUpSociCon.Open();
Panel updatesocial = (Panel)EditUsrInfoFVw.FindControl("updatesocialpanel");
DataSet ShwUpSocids = new DataSet();
SqlDataAdapter ShwUpSociADP = new SqlDataAdapter(@"SELECT * from UserInfo WHERE [UID] = @USER and UsrType = 'Business'", sc);
var use = Session["UsrNme"];
ShwUpSociADP.SelectCommand.Parameters.AddWithValue("@USER", use);
ShwUpSociADP.Fill(ShwUpSocids);
if (ShwUpSocids.Tables[0].Rows.Count > 0)
{
updatesocial.Visible = true;
}
else
{
updatesocial.Visible = false;
}
}
}
else
{
viwapplipanel.Visible = false;
}
}
Below code is to bind the listview and it locate into page_load:
if (Session["UsrNme"] != null)
{
using (SqlConnection HPPersInfoCon = new SqlConnection(sc))
{
HPPersInfoCon.Open();
SqlDataAdapter HPPersInfoSQLAD = new SqlDataAdapter(@"SELECT * From UserInfo Where UID=@UID", sc);
var usrinfoHP = Session["UsrNme"];
HPPersInfoSQLAD.SelectCommand.Parameters.AddWithValue("@UID", usrinfoHP);
DataSet HPPersInfoDS = new DataSet();
HPPersInfoSQLAD.Fill(HPPersInfoDS);
HPPersInfoLV.DataSource = HPPersInfoDS.Tables[0];
HPPersInfoLV.DataBind();
}
}