ASP.NET GridView控件绑定数据问题
只能显示数据库中的一条数据(第一条或最后一条),请高手指教(gvStuInfo是GridView控件的名称)publicpartialclassHouAdmin_zhuc...
只能显示数据库中的一条数据(第一条或最后一条),请高手指教(gvStuInfo是GridView控件的名称)
public partial class HouAdmin_zhuce_stu : System.Web.UI.Page
{
Datacon dataconn = new Datacon();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dataconn.ecadabindinfostring(gvStuInfo, "select * from tb_Student ", "ID");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvStuInfo.PageIndex = e.NewPageIndex;
dataconn.ecadabind(gvStuInfo, "Select * From tb_Student Where "
+ ddlStuID.SelectedValue + " Like '%" + txtSelect.Text + "%'");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtSelect.Text == "")
{
dataconn.ecadabindinfostring(gvStuInfo, "select * from tb_Student ", "ID");
}
else
{
dataconn.ecadabind(gvStuInfo, "Select * From tb_Student Where "
+ ddlStuID.SelectedValue + " Like '%" + txtSelect.Text + "%'");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
dataconn.eccom("delete from tb_Student where ID='" + gvStuInfo.DataKeys[e.RowIndex].Value + "'");
Page.Response.Redirect("zhuce_stu.aspx");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Text = Convert.ToString(Convert.ToDateTime(e.Row.Cells[4].Text).ToShortDateString());
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (TreeView1.SelectedNode.Text == "退出系统")
{
Response.Write("<script lanuage=javascript>window.close();location='javascript:history.go(-1)'</script>");
}
}
} 展开
public partial class HouAdmin_zhuce_stu : System.Web.UI.Page
{
Datacon dataconn = new Datacon();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dataconn.ecadabindinfostring(gvStuInfo, "select * from tb_Student ", "ID");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvStuInfo.PageIndex = e.NewPageIndex;
dataconn.ecadabind(gvStuInfo, "Select * From tb_Student Where "
+ ddlStuID.SelectedValue + " Like '%" + txtSelect.Text + "%'");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtSelect.Text == "")
{
dataconn.ecadabindinfostring(gvStuInfo, "select * from tb_Student ", "ID");
}
else
{
dataconn.ecadabind(gvStuInfo, "Select * From tb_Student Where "
+ ddlStuID.SelectedValue + " Like '%" + txtSelect.Text + "%'");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
dataconn.eccom("delete from tb_Student where ID='" + gvStuInfo.DataKeys[e.RowIndex].Value + "'");
Page.Response.Redirect("zhuce_stu.aspx");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Text = Convert.ToString(Convert.ToDateTime(e.Row.Cells[4].Text).ToShortDateString());
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (TreeView1.SelectedNode.Text == "退出系统")
{
Response.Write("<script lanuage=javascript>window.close();location='javascript:history.go(-1)'</script>");
}
}
} 展开
展开全部
绑定数据的方法有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
关注中.....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
input type=submit/button/text runat=server
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Text = Convert.ToString(Convert.ToDateTime(e.Row.Cells[4].Text).ToShortDateString());
}
}
怎么只判断绑定一列?其他列都不绑定了?
还有e.Row.RowType == DataControlRowType.DataRow这个描述不对吧,这里我记得是两个判断,一个判断的话不能实现。还有个应该是判断e.row的数据类别是不是绑定列,你可以去vs里面找找,我记不清楚是怎么写的了。
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Text = Convert.ToString(Convert.ToDateTime(e.Row.Cells[4].Text).ToShortDateString());
}
}
怎么只判断绑定一列?其他列都不绑定了?
还有e.Row.RowType == DataControlRowType.DataRow这个描述不对吧,这里我记得是两个判断,一个判断的话不能实现。还有个应该是判断e.row的数据类别是不是绑定列,你可以去vs里面找找,我记不清楚是怎么写的了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询