我有一個網格名稱=在該網格gvDetails我有一個下拉也爲頁面導航對象引用不設置爲一個對象的一個實例中的GridView
protected void gvDetails_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = gvDetails.BottomPagerRow;
DropDownList pageList =
(DropDownList的)pagerRow.Cells [0 ] .FindControl( 「PageDropDownList」);
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
if (pageList != null)
{
for (int i = 0; i < gvDetails.PageCount; i++)
{
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
if (i == gvDetails.PageIndex)
{
item.Selected = true;
}
pageList.Items.Add(item);
}
}
if (pageLabel != null)
{
int currentPage = gvDetails.PageIndex + 1;
}
}
----- * ** * ** ----------
這是填充編碼我有
protected void gvDetails_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = gvDetails.BottomPagerRow;
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
if (pageList != null)
{
for (int i = 0; i < gvDetails.PageCount; i++)
{
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
if (i == gvDetails.PageIndex)
{
item.Selected = true;
}
pageList.Items.Add(item);
}
}
if (pageLabel != null)
{
int currentPage = gvDetails.PageIndex + 1;
}
}
protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
{
GridViewRow pagerRow = gvDetails.BottomPagerRow;
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
gvDetails.PageIndex = pageList.SelectedIndex;
}
private void LoadBindGrid()
{
////Set your connection String here
SqlConnection CN = DBUtil.GetCon();
if (CN.State != ConnectionState.Closed)
CN.Close();
CN.Open();
string q = "SELECT Head_Code,Head_Name,Section_Code,Head_Mode,Head_Type,Head_Status FROM eLogs_Acc_Account_Master";
SqlCommand cmd = new SqlCommand(q, CN);
//SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=True");
////Write a select Query
//string q = "select CustomerID,CompanyName,ContactName,Phone,City,Country from Customers";
DataSet dset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(q, CN);
//cn.Open();
DataTable dtable = new DataTable();
da.Fill(dtable);
//Bind grid.
gvDetails.DataSource = dtable;
gvDetails.DataBind();
CN.Close();
}
未將對象引用設置爲對象的實例。 (DropDownList pageList =(DropDownList)pagerRow.Cells [0] .FindControl(「PageDropDownList」);) 請幫助
究竟哪一行?顯然有些變量是未設置的,但不知道哪一個是不可能說**爲什麼** – ChrisF
DropDownList pageList =(DropDownList)pagerRow.Cells [0] .FindControl(「PageDropDownList」);這一行我有錯誤 – Rajkumar
對象引用arror我被清除我想綁定數據的網格我應該如何綁定數據 – Rajkumar