GridView中数据行的操作


一个是直接动态绑定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();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM