GridView控件提供管理审核过滤问题
//GridView设置显示信息
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Font-Size="9pt" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="信息ID" />
<asp:BoundField DataField="name" HeaderText="信息主题" />
<asp:BoundField DataField="type" HeaderText="信息分类" />
<asp:BoundField DataField="userName" HeaderText="发布人" />
<asp:BoundField DataField="lineMan" HeaderText="联系人" />
<asp:BoundField DataField="term" HeaderText="有效期" DataFormatString="{0:d}" />
<asp:BoundField DataField="check" HeaderText="审核" />
<asp:CommandField HeaderText="通过/取消" SelectText="通过/取消" ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Right" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//绑定数据信息显示经过数据库审核的过滤信息
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conStr"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GV_DataBind();
}
}
public void GV_DataBind()
{
string sqlstr = "select * from tb_inf ";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon);
DataSet ds = new DataSet();
sqlcon.Open();
da.Fill(ds);
sqlcon.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[6].Text == "False")
{ e.Row.Cells[6].Text = "<font color=red>已通过</font>";
}
else
{
e.Row.Cells[6].Text = "未通过";
}
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
sqlcon = new SqlConnection(strCon);
SqlCommand com = new SqlCommand("select [check] from tb_inf where id='" + id + "'", sqlcon);
sqlcon.Open();
string count = Convert.ToString(com.ExecuteScalar());
if (count == "False")
{
count = "1";
}
else
{
count = "0";
}
com.CommandText = "update tb_inf set [check]=" + count + " where id=" + id;
com.ExecuteNonQuery();
sqlcon.Close();
this.GV_DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex= e.NewPageIndex;
this.GV_DataBind();
}
//GridView设置显示信息
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Font-Size="9pt" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="信息ID" />
<asp:BoundField DataField="name" HeaderText="信息主题" />
<asp:BoundField DataField="type" HeaderText="信息分类" />
<asp:BoundField DataField="userName" HeaderText="发布人" />
<asp:BoundField DataField="lineMan" HeaderText="联系人" />
<asp:BoundField DataField="term" HeaderText="有效期" DataFormatString="{0:d}" />
<asp:BoundField DataField="check" HeaderText="审核" />
<asp:CommandField HeaderText="通过/取消" SelectText="通过/取消" ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Right" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//绑定数据信息显示经过数据库审核的过滤信息
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conStr"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GV_DataBind();
}
}
public void GV_DataBind()
{
string sqlstr = "select * from tb_inf ";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon);
DataSet ds = new DataSet();
sqlcon.Open();
da.Fill(ds);
sqlcon.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[6].Text == "False")
{ e.Row.Cells[6].Text = "<font color=red>已通过</font>";
}
else
{
e.Row.Cells[6].Text = "未通过";
}
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
sqlcon = new SqlConnection(strCon);
SqlCommand com = new SqlCommand("select [check] from tb_inf where id='" + id + "'", sqlcon);
sqlcon.Open();
string count = Convert.ToString(com.ExecuteScalar());
if (count == "False")
{
count = "1";
}
else
{
count = "0";
}
com.CommandText = "update tb_inf set [check]=" + count + " where id=" + id;
com.ExecuteNonQuery();
sqlcon.Close();
this.GV_DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex= e.NewPageIndex;
this.GV_DataBind();
}
解决方案 »
- 连接oracle数据库
- 关于批量上传图片的问题/???
- datalist或者是页面的列的控制问题
- TreeView的checkbox在PopulateOnDemand情况下的联动问题
- 请问大家一个很难的问题:[高分]
- VS2003中无法调试ASP.NET程序,请高手帮忙!!!
- ASP.NET如何处理图像
- 高难问题Infragistics NetAdvantage 2004 Vol. 3 布属和使用.
- 介绍些关于 asp.net 2.0 中 web part 的站点或文章给我看看 谢谢了
- 点击表头linkbut按钮如何让datalist升降排序
- .NET集成支付宝接口出现错误:ILLEGAL_PARTNER
- 急急急!本人菜鸟求帮助。asp项目在iis部署后,只出来标题,在vs2010中调试后,可进入登入界面,但输入用户名和密码后报错如图
或者在绑定事件里面进行数据动态绑定也可以
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataView dw = dt().DefaultView;
//这里假设我们筛选字段为ID
dw.RowFilter = " ID='" + DropDownList1.SelectedItem.Text + "'";
GridView1.DataSource = dw;
GridView1.DataBind();
}