我收到此错误但未发现问题:
对象引用未设置为对象的实例。
我的代码:
Page Init:
else if (Request.QueryString["CompanyID"] != null)
{
pnlComp.Visible = true;
if (Convert.ToString(ViewState["Generated"]) != "true")
{
createCompSite();
ViewState["Generated"] = "true";
}
}
页面加载:
Verification.Check();
if (!IsPostBack)
{
sFilter= null;
FillGridviewAndValues();
}
if (Convert.ToString(ViewState["Generated"]) == "true")
createCompSite();
功能:
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);
}
我想创建一个从DataBase填充的表,并且在每个站点上看起来可能不同,并且每个表格单元应该具有引导用户的不同链接。表创建从init。页面开始。