网格视图数据绑定问题 [英] Grid View data bind issues

查看:75
本文介绍了网格视图数据绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我正在做网格示例...尽管没有错误,Databind到网格没有显示.. 。这是代码。





  protected   void  btnSearch_Click( object  sender,EventArgs e)
{
sqlcon = new SqlConnection(strconn);
cmd = new SqlCommand( searchCriteriaSP ,sqlcon); // 调用存储过程
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
da.SelectCommand.Parameters.AddWithValue( @ input,SqlDbType.VarChar)。 Value = ddlSearch.SelectedValue; // 将参数传递给数据库的过程
da.Fill(ds);
if (ds.Tables [ 0 ]。Rows.Count > 0
{
GridView1.DataSource = ds;
GridView1.DataBind();
}

}









任何想法......

解决方案

试试这个:

  protected   void  btnSearch_Click( object  sender,EventArgs e)
{
sqlcon = new SqlConnection(strconn);
cmd = new SqlCommand( searchCriteriaSP ,sqlcon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( new SqlParameter( @input,SqlDbType.VarChar))。Value = ddlSearch.SelectedValue;
da = new SqlDataAdapter(cmd);
da.Fill(ds);
if (ds.Tables [ 0 ]。Rows.Count > 0
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
}







- Amit

Hi,


I was doing grid sample...Databind to grid is not displaying though there is no error...Here is the code.


protected void btnSearch_Click(object sender, EventArgs e)
       {
           sqlcon = new SqlConnection(strconn);
           cmd = new SqlCommand("searchCriteriaSP", sqlcon); // calling the stored procedure
           cmd.CommandType = CommandType.StoredProcedure;
           da = new SqlDataAdapter(cmd);
           da.SelectCommand.Parameters.AddWithValue("@input", SqlDbType.VarChar).Value = ddlSearch.SelectedValue; // passing parameter to the procedure to the database
           da.Fill(ds);
           if (ds.Tables[0].Rows.Count > 0)
           {
               GridView1.DataSource = ds;
               GridView1.DataBind();
           }

       }





Any idea...

解决方案

Try this:

protected void btnSearch_Click(object sender, EventArgs e)
{
   sqlcon = new SqlConnection(strconn);
   cmd = new SqlCommand("searchCriteriaSP", sqlcon); 
   cmd.CommandType = CommandType.StoredProcedure;
   cmd.Parameters.Add(new SqlParameter("@input", SqlDbType.VarChar)).Value = ddlSearch.SelectedValue;
   da = new SqlDataAdapter(cmd);
   da.Fill(ds);
   if (ds.Tables[0].Rows.Count > 0)
   {
       GridView1.DataSource = ds;
       GridView1.DataBind();
   }
}




--Amit


这篇关于网格视图数据绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆