当我尝试阅读时,GridView错误,从SQL Server显示项目信息

发布于 2025-02-10 11:19:34 字数 1027 浏览 2 评论 0原文

我得到这个错误:

汇编错误

描述:在为此请求的资源的汇编过程中,发生了错误。请查看以下特定错误详细信息并适当修改您的源代码。

编译器错误消息:CS1061:'updateForm_aspx'不包含'gridview1_selectedIndexchanged'的定义,而没有扩展方法” gridview1_selectedIndexchanged'接受类型'UpdateForm_aspx'的第一个参数(您是否丢失了使用Directive或使用Directive a Directive或a -nifferage obsessbly或一个组件参考?)

源错误:

Line 49:                 </div>
Line 50:             </div>
Line 51:         <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
Line 52:         </asp:GridView>
Line 53:     </form>

这是我尝试在GridView上显示信息的地方:

SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-62V61RT\SQLEXPRESS; Initial Catalog =ShopOnlineDB; Integrated Security=True;");
con.Open();

SqlCommand cmd = new SqlCommand("Select * from Master.Items", con);

SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
dat.Fill(dt);

GridView1.DataSource = dt;

I get this error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'updateform_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'updateform_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 49:                 </div>
Line 50:             </div>
Line 51:         <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
Line 52:         </asp:GridView>
Line 53:     </form>

This is where I try to show information on GridView:

SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-62V61RT\SQLEXPRESS; Initial Catalog =ShopOnlineDB; Integrated Security=True;");
con.Open();

SqlCommand cmd = new SqlCommand("Select * from Master.Items", con);

SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
dat.Fill(dt);

GridView1.DataSource = dt;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2025-02-17 11:19:34

只需在CS文件中的代码中添加它



 protected void GridView1_SelectedIndexChanged (object sender, EventArgs e)
{
       // you code
}

Just add this in the code in cs file



 protected void GridView1_SelectedIndexChanged (object sender, EventArgs e)
{
       // you code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文