我仍然没有在网络浏览器中获得网格视图 [英] I am still not getting grid view in web browser

查看:66
本文介绍了我仍然没有在网络浏览器中获得网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是代码

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Data.SqlClient;

public partial class _Default:System.Web.UI.Page
{
SqlConnection con = new SqlConnection( 数据源= Jay-PC;初始目录= test1;用户ID = sa;密码= sa @ 123);
SqlCommand cmd;
string sql;

受保护 void Page_Load( object sender,EventArgs e)
{
fill_grid();
}
受保护 void Button1_Click( object sender,EventArgs e)
{
datainsert();
}
public void datainsert()
{

con.Open();
cmd = new SqlCommand( insert into注册(名称,类,性别,email_id)值(@ name,@ class,@ gender,@ email_id),con);
cmd.Parameters.AddWithValue( @ name,(TextBox1.Text));
cmd.Parameters.AddWithValue( @ class,(TextBox2.Text));
cmd.Parameters.AddWithValue( @ gender,(DropDownList1.SelectedValue));
cmd.Parameters.AddWithValue( @ email_id,(TextBox3.Text));
cmd.ExecuteNonQuery();

}
public void fill_grid()
{
sql = select * from registration;
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}

解决方案

可能有很多原因。我建议你调试和处理异常,这样你就可以知道问题究竟在哪里。



如果你无法解决异常或需要更多,请在此处评论帮助

Here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection("Data Source=Jay-PC;Initial Catalog=test1;User ID=sa;Password=sa@123");
    SqlCommand cmd;
    string sql;

    protected void Page_Load(object sender, EventArgs e)
    {
        fill_grid();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        datainsert();
    }
    public void datainsert()
    {
        
        con.Open();
        cmd = new SqlCommand("insert into registration (name,class,gender,email_id)values(@name,@class,@gender,@email_id)", con);
        cmd.Parameters.AddWithValue("@name", (TextBox1.Text));
        cmd.Parameters.AddWithValue("@class", (TextBox2.Text));
        cmd.Parameters.AddWithValue("@gender",(DropDownList1.SelectedValue));
        cmd.Parameters.AddWithValue("@email_id", (TextBox3.Text));
        cmd.ExecuteNonQuery();
        
    }
    public void fill_grid()
    {
        sql="select* from registration";
        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind(); 
        con.Close();
    }
}

解决方案

There might be many reasons. I suggest you to debug and handle exceptions, so that you can know where exactly is the issue.

Comment here if you could not able to resolve the exceptions or need more help.


这篇关于我仍然没有在网络浏览器中获得网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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