gridview如何重新绑定数据库
我点击一个button后就绑定数据库(其中我设置了几个RadioButton来确定是否隐藏特定的列)我一旦点击了这个button后,从新根据其他的条件来绑定GridVie...
我点击一个button后就绑定数据库(其中我设置了几个RadioButton来确定是否隐藏特定的列)
我一旦点击了这个button后,从新根据其他的条件来绑定GridView时,那个Button就没有了重新绑定,一直是出现最开始的绑定的GridView,该怎么做。
代码如下
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConn = GetConnection();
sqlConn.Open();
string sqlStr = "select * from jb";
SqlCommand sqlCom = new SqlCommand(sqlStr, sqlConn);
SqlDataReader dr = sqlCom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
int i = 0;
foreach (Control control in this.Form.Controls)
{
if (control is RadioButton)
{
RadioButton radio = (RadioButton)control;
if (radio.Checked != true)
{
GridView1.Columns[i].Visible = false;
}
i = i + 1;
}
}
} 展开
我一旦点击了这个button后,从新根据其他的条件来绑定GridView时,那个Button就没有了重新绑定,一直是出现最开始的绑定的GridView,该怎么做。
代码如下
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConn = GetConnection();
sqlConn.Open();
string sqlStr = "select * from jb";
SqlCommand sqlCom = new SqlCommand(sqlStr, sqlConn);
SqlDataReader dr = sqlCom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
int i = 0;
foreach (Control control in this.Form.Controls)
{
if (control is RadioButton)
{
RadioButton radio = (RadioButton)control;
if (radio.Checked != true)
{
GridView1.Columns[i].Visible = false;
}
i = i + 1;
}
}
} 展开
2个回答
展开全部
你写到方法里再调用就行了;
注意回发的问题
在PageLoad中写上
if(!Ispostback)
{banding();}
再定义一个函数
private void danding()
{
SqlConnection sqlConn = GetConnection();
sqlConn.Open();
string sqlStr = "select * from jb";
SqlCommand sqlCom = new SqlCommand(sqlStr, sqlConn);
SqlDataReader dr = sqlCom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
int i = 0;
foreach (Control control in this.Form.Controls)
{
if (control is RadioButton)
{
RadioButton radio = (RadioButton)control;
if (radio.Checked != true)
{
GridView1.Columns[i].Visible = false;
}
i = i + 1;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
banding();
}
就ok了
注意回发的问题
在PageLoad中写上
if(!Ispostback)
{banding();}
再定义一个函数
private void danding()
{
SqlConnection sqlConn = GetConnection();
sqlConn.Open();
string sqlStr = "select * from jb";
SqlCommand sqlCom = new SqlCommand(sqlStr, sqlConn);
SqlDataReader dr = sqlCom.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
int i = 0;
foreach (Control control in this.Form.Controls)
{
if (control is RadioButton)
{
RadioButton radio = (RadioButton)control;
if (radio.Checked != true)
{
GridView1.Columns[i].Visible = false;
}
i = i + 1;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
banding();
}
就ok了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询