如何通过listbox中selectindexchange 来改变girdview中的数据值,我不能联动,不知什么原因?部分主要代码如下
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowUnit();
BindGridView();
}
}
private void BindGridView()
{
string sqlStr = "select fid,fno,fdirname,funame,fdate,find from tfile where find like '" + LBunit.SelectedValue.ToString()+"'";
DataSet dataset = dsc.myAdapeter(sqlStr);
try
{
GridView1.DataSource = dataset;
GridView1.DataKeyNames = new String[] { "fid" };
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
finally
{
// 释放占有资源
}
lblCurrentIndex.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";
lblPageCount.Text = "总共" + GridView1.PageCount.ToString() + "页";
lblRecordCount.Text = "总共" + dataset.Tables[0].Rows.Count.ToString() + "条";
if (dataset.Tables[0].Rows.Count == 0)
{
lnkbtnFirst.Visible = false;
lnkbtnPre.Visible = false;
lnkbtnNext.Visible = false;
lnkbtnLast.Visible = false;
lblCurrentIndex.Visible = false;
lblPageCount.Visible = false;
lblRecordCount.Visible = false;
}
else if (GridView1.PageCount == 1)
{
lnkbtnFirst.Visible = false;
lnkbtnPre.Visible = false;
lnkbtnNext.Visible = false;
lnkbtnLast.Visible = false;
}
lnkbtnFirst.CommandArgument = "1";
lnkbtnPre.CommandArgument = (GridView1.PageIndex == 0 ? "1" : GridView1.PageIndex.ToString());
lnkbtnNext.CommandArgument = (GridView1.PageCount == 1 ? GridView1.PageCount.ToString() : (GridView1.PageIndex + 2).ToString());
lnkbtnLast.CommandArgument = GridView1.PageCount.ToString();
}
//跳转
protected void lnkbtnJumpPage_Click(object sender, EventArgs e)
{
GridView1.PageIndex = Convert.ToInt32(txtJumpPage.Text) - 1;
lblCurrentIndex.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";
BindGridView();
}
protected void PagerButtonClick(object sender, EventArgs e)
{
GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandArgument) - 1;
BindGridView();
}
protected void ShowUnit()
{
string sqlStr = "select * from tunit";
DataSet ds = dsc.myAdapeter(sqlStr);
this.LBunit.DataSource = ds;
this.LBunit.DataTextField = "uname";
this.LBunit.DataValueField = "uid";
this.LBunit.DataBind();
this.LBunit.SelectedIndex = 0;
}
protected void LBunit_SelectedIndexChanged(object sender, EventArgs e)
{
} --------------------编程问答-------------------- 在SelectedIndexChanged中添加以下代码:
protected void LBunit_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridView();
}
补充:.NET技术 , ASP.NET