一個是直接動態綁定gridview 用3樓的辦法就可以了
int j=1;//j的數值表示你要取的那一列的索引,要取第二列,j就設為1
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
str[i]= this.GridView1.Rows[i].Cells[j].Text;//str[i]就存放了gridview1中第i行第2列的值
}
二個是模板化的gridview (模板化的可以改變列的位置,控制列的隱藏顯示,以及編輯等功能) 就要用
TextBox Tb=(TextBox)GridView1.Rows[i].Cell[1].FindControl("TextBox1");
string str=tb.text.tostring() 的方法獲取值,如果是Label,DropDownlist 換過來就是了。因為用模板的時候.GridView1.Rows[i].Cells[j].Text 這樣的語句是取不到值的
為GridView綁定數據的時候可以設制多個參數列以便在處理數據時用到作為條件增刪改查如下:
DataSet ds = bll.GetAll(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, out count, Request.QueryString["LendNum"].ToString());
AspNetPager1.RecordCount = count;
HT_LoanInformationGrid.DataSource = ds.Tables[0].DefaultView;
HT_LoanInformationGrid.DataKeyNames = new string[] { "MortgageDetail" ,"Params2"};
HT_LoanInformationGrid.DataBind();
到用時就用
string loanerId = HT_LoanInformationGrid.DataKeys[0].Value.ToString();
string loanerId = HT_LoanInformationGrid.DataKeys[1].Value.ToString();