在插入Templatefied绑定后我没有得到gridview。但是数据插入到sqlserver但是没有出现网格 [英] I am not getting the gridview after the insertion of Templatefied binding..But the data inserted into sqlserver but grid is not appear

查看:70
本文介绍了在插入Templatefied绑定后我没有得到gridview。但是数据插入到sqlserver但是没有出现网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IN Cs



IN Cs

protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           TextBox1.Focus();
           gvbind();
       }
   }
       private void gvbind()
       {
           obj.type=0;
           ds = obj.DataSet();
           GridView1.DataSource = ds;
           GridView1.DataBind();}



在Sql server中


In Sql server

if @type=0
select * from app

推荐答案

尝试像这样的BindGrid



private void BindGrid()

{

DataSet ds = new DataSet();

SqlConnection Conn = new SqlConnection(con);

{

Conn.Open();

SqlCommand cmd = new SqlCommand(Select * from ProductInfo,Conn);

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(ds);

Conn.Close();

gvDetails.DataSource = ds;

gvDetails.DataBind();



}

}
Try BindGrid Like This

private void BindGrid()
{
DataSet ds = new DataSet();
SqlConnection Conn = new SqlConnection(con);
{
Conn.Open();
SqlCommand cmd = new SqlCommand("Select * from ProductInfo",Conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Conn.Close();
gvDetails.DataSource = ds;
gvDetails.DataBind();

}
}


你好,



立即postba ck响应按钮点击你没有调用gvBind()所以它看起来你无法获得并看到gridview控件。你需要调用gvBind(),如下所示,每次回发或非回发意味着首先加载你应该能够绑定数据看看网格控件。你可以尝试如下 -



Hi,

On immediate postback in response to button click you are not calling gvBind() so it looks you are not able to get and see gridview control. You need to call gvBind() as below so on every postback or non-postback means first load you should be able to bind data see grid control. Can you try as below -

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      TextBox1.Focus();
   }
   gvbind(); // on every page load it will bind data to grid control.
}


这篇关于在插入Templatefied绑定后我没有得到gridview。但是数据插入到sqlserver但是没有出现网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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