Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > สอบถามปัญหา Error RowDataBound ของ Gridview ครับ ภาษา ASP.NET C# ครับ



 

สอบถามปัญหา Error RowDataBound ของ Gridview ครับ ภาษา ASP.NET C# ครับ

 



Topic : 071585



โพสกระทู้ ( 24 )
บทความ ( 0 )



สถานะออฟไลน์




เนื่องจากได้ศึกษาจากหัวข้อ
https://www.thaicreate.com/asp.net/c-sharp-asp.net-gridview-control-databound.html

เพื่อจะทดลองสร้าง hyper link ใน grid view แต่ตอนนี้พบ Error นี้ครับ

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


โดย code ที่ทดลองทำเป็นดังนี้ครับ

Code (ASP)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sai.aspx.cs" Inherits="MedicalWeb.sai" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False" 
onRowDataBound="myGridView_RowDataBound">

	<Columns>

	<asp:TemplateField HeaderText="CustomerID">
		<ItemTemplate>
			<asp:Label id="lblCustomerID" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	<asp:TemplateField HeaderText="Name">
		<ItemTemplate>
			<asp:Label id="lblName" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	<asp:TemplateField HeaderText="Email">
		<ItemTemplate>
			<asp:Label id="lblEmail" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	<asp:TemplateField HeaderText="CountryCode">
		<ItemTemplate>
			<asp:Label id="lblCountryCode" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	<asp:TemplateField HeaderText="Budget">
		<ItemTemplate>
			<asp:Label id="lblBudget" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	<asp:TemplateField HeaderText="Used">
		<ItemTemplate>
			<asp:Label id="lblUsed" runat="server"></asp:Label>
		</ItemTemplate>
	</asp:TemplateField>

	</Columns>
</asp:GridView>
</form>
</body>
</html>


ส่วน code behind ครับ

Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Text;
using System.Xml;
using System.Collections.Generic;
using System.Net;
using System.IO;

namespace MedicalWeb
{
    public partial class sai : System.Web.UI.Page
    {
        SqlConnection objConn;
        SqlCommand objCmd;
        String strSQL;
        private string connectionString = WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            objConn = new SqlConnection(connectionString);
            objConn.Open();
            BindData();
        }

        void BindData()
        {
            String strSQL;
            strSQL = "SELECT PanId, Name, Surname,Sex,Age,Inhospital FROM PanInfo WHERE Username = 'amuds'";
            SqlDataReader dtReader;
            objCmd = new SqlCommand(strSQL, objConn);
            dtReader = objCmd.ExecuteReader();

            //*** BindData to GridView ***//
            myGridView.DataSource = dtReader;
            myGridView.DataBind();
            dtReader.Close();
            dtReader = null;
        }

        void Page_UnLoad()
        {
            objConn.Close();
            objConn = null;
        }

        void myGridView_RowDataBound(Object s, GridViewRowEventArgs e) 
	    {
		//*** CustomerID ***//
		Label lblCustomerID = (Label)(e.Row.FindControl("lblCustomerID"));
		if (lblCustomerID != null)
		{
			lblCustomerID.Text = (string)DataBinder.Eval(e.Row.DataItem, "PanId");
		}

		//*** Email ***//
		Label lblName = (Label)(e.Row.FindControl("lblName"));
		if (lblName != null)
		{
			lblName.Text = (string)DataBinder.Eval(e.Row.DataItem, "Name");
		}

		//*** Name ***//
		Label lblEmail = (Label)(e.Row.FindControl("lblEmail"));
		if (lblEmail != null)
		{
			lblEmail.Text = (string)DataBinder.Eval(e.Row.DataItem, "Surname");
		}

		//*** CountryCode ***//
		Label lblCountryCode = (Label)(e.Row.FindControl("lblCountryCode"));
		if (lblCountryCode != null)
		{
			lblCountryCode.Text = (string)DataBinder.Eval(e.Row.DataItem, "Sex");
		}

		//*** Budget ***//
		Label lblBudget = (Label)(e.Row.FindControl("lblBudget"));
		if (lblBudget != null)
		{
			//lblBudget.Text = DataBinder.Eval(e.Row.DataItem, "Budget").ToString();
            lblBudget.Text = (string)DataBinder.Eval(e.Row.DataItem, "Age");
		}

		//*** Used ***//
		Label lblUsed = (Label)(e.Row.FindControl("lblUsed"));
		if (lblUsed != null)
		{
			//lblUsed.Text = DataBinder.Eval(e.Row.DataItem, "Used").ToString();
            lblUsed.Text = (string)DataBinder.Eval(e.Row.DataItem, "Inhospital");
		}

    }
}


ไม่ทราบว่าต้องแก้ปัญหาอย่างไรครับ ขอบคุณล่วงหน้าครับ ติดมาอยู่ 2 วันแล้ว
นอกจากนั้นแล้ว onModeChanging หรือ OnItemUpdating ก็มี Error ลักษณะเดียวกันครับ



Tag : ASP.NET, Ms SQL Server 2008, Web (ASP.NET), C#, VS 2010 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-01-09 15:10:16 By : amuds View : 2512 Reply : 4
 

 

No. 1



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


ดูผิวเผินยังไม่ได้เอาไปลอง Run นะครับ สังเกตเห็นว่าปีกกาหายไป 1 บรรทัด ที่บรรทัด 101 ไม่มี } เพื่อปิด void myGridView_RowDataBound ใช่หรือไม่ ลองตรวจสอบดู เพราะ Error เป็น Compiler Error ไม่ใช่ Runtime Error นะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-09 15:50:23 By : gunnermontana
 


 

No. 2



โพสกระทู้ ( 24 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : gunnermontana เมื่อวันที่ 2012-01-09 15:50:23
รายละเอียดของการตอบ ::
อ๋อใช่ครับ ผมพิมตกไปเองครับ แต่ยังไงก็ยังขึ้น Error เดิมครับ

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

Source Error:


Line 9: <body>
Line 10: <form id="form1" runat="server">
Line 11: <asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False" onRowDataBound="myGridView_RowDataBound">
Line 12:
Line 13: <Columns>




ประวัติการแก้ไข
2012-01-09 16:05:56
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-09 16:00:45 By : amuds
 

 

No. 3



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


สังเกตดี ๆ นะครับที่ Code Behind การประกาศ Method

Code (C#)
void myGridView_RowDataBound(Object s, GridViewRowEventArgs e)


มีการอ้าง Reference ที่ผิด โดยต้องแก้เป็น

Code (C#)
protected void myGridView_RowDataBound(Object s, GridViewRowEventArgs e)


หน้า Front มันไม่รู้จัก Event นะครับ มันก็เลย Error ออกมาแบบนั้น
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-09 16:54:46 By : gunnermontana
 


 

No. 4



โพสกระทู้ ( 24 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : gunnermontana เมื่อวันที่ 2012-01-09 16:54:46
รายละเอียดของการตอบ ::
ขอบคุณครับ เป็นไปตามที่บอกเลยครับ
ขอบคุณสำหรับความรู้ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-01-09 17:06:59 By : amuds
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามปัญหา Error RowDataBound ของ Gridview ครับ ภาษา ASP.NET C# ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่