数据未在GridView1中显示 [英] data not shown in GridView1

查看:63
本文介绍了数据未在GridView1中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面写了这个html代码 -



 <   td     align   =  center >  
< asp:LinkBut​​ton ID = viewdata runat = 服务器 onclick = viewdata_Click >
viewdata < / asp:LinkBut​​ton >
< br / >
< asp:GridView ID = GridView1 runat = 服务器 >
< / asp:GridView > ;
< / td >









我已经在我的cs页面中编写了这段代码:: -



  protected   void  viewdata_Click( object  sender,EventArgs e) //  要查看的代码 

/// /来自SQL Server的数据
{
SqlConnection conn = new SqlConnection ( user id = sa; +
password = prodip @ km; server = PRODIP; +
Trusted_Connection = yes; +
database = Member;);
try
{
SqlDataAdapter sda = new SqlDataAdapter( select * from emp,conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();

}
}





但问题是==以下两行显示为红色下划线&显示混乱

GridView1不会在当前上下文中退出..

该行是 -



GridView1.DataSource = ds;

GridView1.DataBind();





请帮帮我哪里是我的错误..

解决方案

请按照以下2来解决您的问题..

GridView错误'在当前上下文中不存在' [ ^ ]

当前上下文中没有名称'GridView1'Glossary.aspx.cs [ ^ ]

外貌就像你从其他项目中复制了aspx代码一样。有时,当从某个地方复制文本而不是在窗体上拖放控件时,Visual Studio不会添加控件。如果是这种情况,您可以删除现有的gridview控件并尝试再次添加。


I have written this html code in aspx page--

<td align="center">
<asp:LinkButton ID="viewdata" runat="server" onclick="viewdata_Click">
    viewdata</asp:LinkButton>
    <br />
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
</td>





And i have written this code in my cs page::--

protected void viewdata_Click(object sender, EventArgs e)//Code to View 

        //// the data from the SQL Server
    {
        SqlConnection conn = new SqlConnection("user id=sa;" +
                                       "password=prodip@km;server=PRODIP;" +
                                       "Trusted_Connection=yes;" +
                                       "database=Member;");
        try
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from emp", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();

        }
}



But the problem is ==the following two line shown as red underline & show the mess that
GridView1 dose not exit in current context..
the line are--

GridView1.DataSource = ds;
GridView1.DataBind();


please help me where is my mistake..

解决方案

Follow these 2 which will help to solve your problem..
GridView error 'does not exist in current context' [^]
The name 'GridView1' does not exist in the current context Glossary.aspx.cs[^]


Looks like you have copied aspx code from other project. Sometime Visual studio does not add controls when text is copied from somewhere rather than dragging and dropping controls on form. If that is the case, you can remove your existing gridview control and try to add it again.


这篇关于数据未在GridView1中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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