- 爱易网页
-
ASP.NET教程
- 关于gridview中使用dropdownlist并启用分页后产生的有关问题
日期:2014-05-18 浏览次数:20456 次
求助关于gridview中使用dropdownlist并启用分页后产生的问题
在gridview的模板列中使用dropdownlist绑定数据库中的数据后,并启用了分页功能后,第1页正常,dropdownlist中有显示数据;但转到第2页后dropdownlist就空了,再转到第1页(不是后退)也没有数据显示了,要再重新LOAD这个页面后,第1页的dropdownlist才会有数据。请问这个该如何解决,谢谢!
部分代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetReceiver();
}
}
private void GetReceiver()
{
string sql = "SELECT OutBoxDetail.OutBoxDetailId, OutBoxDetail.OutBoxId, OutBoxDetail.ReceiverId, UserInfo.UserId, UserInfo.LoginName, UserInfo.UserName, UserInfo.Gender, UserInfo.Mobile, UserInfo.Remark FROM OutBoxDetail INNER JOIN UserInfo ON OutBoxDetail.ReceiverId = UserInfo.UserId ";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "ConnectionString "].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "OutBox ");
for (int i = 0; i < gvOutBox.Rows.Count; i++)
{
GridViewRow row = gvOutBox.Rows[i];
int OutBoxId = int.Parse(row.Cells[0].Text);
DropDownList ddrReceiver = (DropDownList)row.FindControl ( "ddrReceiver ");
DataView dv = ds.Tables[ "OutBox "].DefaultView;
dv.RowFilter = "OutBoxId = " + OutBoxId.ToString();
ddrReceiver.DataSource = dv;
ddrReceiver.DataTextField = "UserName ";
ddrReceiver.DataBind();
}
}
关于以下EXCEL报表,请教高手们该如何实现