I get this error and do not find the problem:
Object reference not set to an instance of an object.
My Code:
Page Init:
else if (Request.QueryString["CompanyID"] != null)
{
pnlComp.Visible = true;
if (Convert.ToString(ViewState["Generated"]) != "true")
{
createCompSite();
ViewState["Generated"] = "true";
}
}
Page Load:
Verification.Check();
if (!IsPostBack)
{
sFilter= null;
FillGridviewAndValues();
}
if (Convert.ToString(ViewState["Generated"]) == "true")
createCompSite();
Function:
TableHeaderRow tHRow = new TableHeaderRow();
TableHeaderCell tHeader = new TableHeaderCell();
tHeader.Text = dr.Field<string>("Loc");
tHRow.Cells.Add(tHeader);
tblCompLoc1.Rows.Add(tHRow);
DataTable dtCat = new DataTable();
dtCat = SQLCon.SQLCommand_DokuTool("SELECT CL.ID, C.CatName FROM TBL_Ref_CatLoc AS CL, TBL_Category AS C WHERE C.CatID = CL.CatID AND CL.LocID = '" + dr.Field<Guid>("ID").ToString() + "' AND CL.Approved='True' ORDER BY CatName ASC");
foreach (DataRow dr2 in dtCat.Rows)
{
//Working as plain Text
//TableRow tRow = new TableRow();
//TableCell tCell = new TableCell();
//tCell.Text = dr2.Field<string>("CatName");
//tRow.Cells.Add(tCell);
//tblCompLoc1.Rows.Add(tRow);
//Not working as Hyperlink or Btn
TableRow tRow = new TableRow();
TableCell tCell = new TableCell();
HyperLink hl = new HyperLink();
hl.EnableViewState=true;
hl.Text = dr2.Field<string>("CatName");
string gLocID = SQLCon.SQLCommand_User("SELECT ID FROM TBL_Location WHERE fCompanyID = '"+sRequest+"' AND City + ', ' + Street1 ='"+tHeader.Text+"'").Rows[0].Field<Guid>("ID").ToString();
string gCatID = SQLCon.SQLCommand_DokuTool("SELECT CatID FROM TBL_Category WHERE CatName='"+hl.Text+"'").Rows[0].Field<Guid>("CatID").ToString();
string sRequestedCat = SQLCon.SQLCommand_DokuTool("SELECT ID FROM TBL_Ref_CatLoc WHERE LocID = '"+gLocID+"' AND CatID='"+gCatID+"'").Rows[0].Field<Guid>("ID").ToString();
hl.NavigateUrl="~/Default?ID="+sRequestedCat;
tCell.Controls.Add(hl);
tRow.Controls.Add(tCell);
tblCompLoc1.Rows.Add(tRow);
}
I want to create a Table which is filled from DataBase and can look different on each site and every Table Cell should have a different Link where it leads the user. The table creation starts on page init.