|  | 
	                
  
    |  |  
    | 
        
        Error : แบบนี้แก้ไขยังไงคะ เพิ่งเริ่มหัดเขียนคะ รบกวนด้วยนะคะ     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (C#) 
 <%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
	SqlConnection objConn;
	SqlCommand objCmd;
    void Page_Load(object sender,EventArgs e)
	{
		String strConnString;
        strConnString = "Server=localhost;UID=sa;PASSWORD=;database=registration;Max Pool Size=400;Connect Timeout=600;";
		objConn = new SqlConnection(strConnString);
        objConn.Open();
		BindData();
    }
	void BindData()
	{
		String strSQL;
        strSQL = "SELECT * FROM member";
		SqlDataReader dtReader;
		objCmd = new SqlCommand(strSQL, objConn);
		dtReader = objCmd.ExecuteReader();
		
		//*** BindData to Repeater ***//
		myRepeater.DataSource = dtReader;
		myRepeater.DataBind();
		dtReader.Close();
		dtReader = null;
	}
	void Page_UnLoad()
	{
		objConn.Close();
		objConn = null;
	}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - SQL Server</title>
</head>
<body>
	<form id="form1" runat="server">
    <asp:Repeater id="myRepeater" runat="server" DataSourceID="SqlDataSource1">
	<HeaderTemplate>
		<table border="1">
			<tr>
				<th>CustomerID</th>
				<th>Name</th>
				<th>Email</th>
				<th>CountryCode</th>
				<th>Budget</th>
		
			</tr>
	</HeaderTemplate>
	<ItemTemplate>
		<tr>
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Username") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Password") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Email") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Country") %>'></asp:Label></td>
	
		</tr>			
	</ItemTemplate>
	<AlternatingItemTemplate>
		<tr bgcolor="#e8e8e8">
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Username") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Password") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Email") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Country") %>'></asp:Label></td>
           
		</tr>			
	</AlternatingItemTemplate>
	</asp:Repeater>
	    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:registrationConnectionString %>" SelectCommand="SELECT * FROM [manager]"></asp:SqlDataSource>
	</form>
</body>
</html>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-13 19:30:59 | By :
                            songza |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ถ้าเขียนบน Visual Studio จะต้องแยกในรูปแบบของ Code Behind ครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-14 15:21:48 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ถ้าระบุ DataSourceID <asp:Repeater id="myRepeater" runat="server" DataSourceID="SqlDataSource1">
 
 จะไม่สามารถใช้คำสั่งนี้
 myRepeater.DataSource = dtReader;
 
 ให้เลือกใช้อย่างใดอย่างหนึ่ง
 
 
 และอย่าง Mr.Win แนะนำ ก็เป็นสิ่งที่พึงปฏิบัติ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-16 09:03:07 | By :
                            watcharop |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | watcharop ตอบได้ชัดเจนแจ่มแจ้งครับ 
 
 <asp:Repeater id="myRepeater" runat="server" DataSourceID="SqlDataSource1">
 
 มันมี DataSource อยู่แล้ว แล้วไปเรียกให้มัน myRepeater.DataSource = dtReader; อีกที จึง Error ครับ
 
 |  
              | 
 ประวัติการแก้ไข
 2016-03-16 11:15:23
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-16 11:14:42 | By :
                            mitr2009 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วค๊าา  ขอบคุณท่านมาก ๆ เลยนะคะ    
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-16 18:56:49 | By :
                            songza |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2016-03-17 09:03:39 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |