|  | 
	                
  
    |  |  
    | 
        
        update gridview ไม่ครับ รบกวนช่วยดู behind code ให้ผมหน่อยครับว่าถูกหรือเปล่า ขอบคุณครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="Car2Land" AllowSorting="True" CssClass="GridView" AllowPaging="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True">
 <Columns>
 <asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
 <asp:BoundField DataField="Short_Model" HeaderText="Short_Model" SortExpression="Short_Model" />
 <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
 <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
 <asp:BoundField DataField="Color" HeaderText="Color" SortExpression="Color" />
 <asp:BoundField DataField="Gear" HeaderText="Gear" SortExpression="Gear" />
 <asp:BoundField DataField="CC" HeaderText="CC" SortExpression="CC" />
 <asp:BoundField DataField="Detail" HeaderText="Detail" SortExpression="Detail" />
 <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
 <asp:BoundField DataField="Tent" HeaderText="Tent" SortExpression="Tent" />
 <asp:BoundField DataField="Tel" HeaderText="Tel" SortExpression="Tel" />
 </Columns>
 <SelectedRowStyle BackColor="#FFFF80" />
 </asp:GridView>
 <asp:SqlDataSource ID="Car2Land" runat="server" ConnectionString="<%$ ConnectionStrings:Car2Land %>"
 SelectCommand="SELECT [ID_Cars], [Brand], [Short_Model], [Year], [Model], [Color], [Gear], [CC], [Detail], [Price], [Tent], [Tel] FROM [c2l_car_all]"
 UpdateCommand="UPDATE [c2l_car_all] set [Brand] = @Brand, [Short_Model] = @Short_Model, [Year] = @Year, [Model] = @Model, [Color] = @Color, [Gear] = @Gear, [CC] = @CC, [Detail] = @Detail, [Price] = @Price, [Tent] = @Tent, [Tel] = @Tel Where [ID_Cars] = @ID_Cars">
 <UpdateParameters>
 <asp:Parameter  Name="ID_Cars" Type="String" />
 <asp:Parameter  Name="Brand" Type="String" />
 <asp:Parameter  Name="Short_Model" Type="String" />
 <asp:Parameter  Name="Year" Type="Int32" />
 <asp:Parameter  Name="Model" Type="String" />
 <asp:Parameter  Name="Color" Type="String" />
 <asp:Parameter  Name="Gear" Type="String" />
 <asp:Parameter  Name="CC" Type="String" />
 <asp:Parameter  Name="Detail" Type="String" />
 <asp:Parameter  Name="Price" Type="Int32" />
 <asp:Parameter  Name="Tent" Type="String" />
 <asp:Parameter  Name="Tel"  Type="String" />
 </UpdateParameters>
 </asp:SqlDataSource>
 
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2010-07-14 10:28:06 | By :
                          yiam21 | View :
                          1730 | Reply :
                          6 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | มี error แจ้งหรือเปล่าครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-14 15:24:23 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | <asp:Parameter Name="ID_Cars" Type="String" /> <!-- Data type ตรงนี้ต้องเป็น DbType ค่ะ ไม่ใช่ Type ของ .Net -->
 <!-- เขียนคล้ายกันแต่ความหมายคนละอย่างกันค่ะ มันไม่ Auto cast ให้ ไม่ว่าจะเป็น vb.net หรือ c# -->
 
 <asp:Parameter Name="ID_Cars" Type="DbType.AnsiString" />
 ....
 <asp:Parameter Name="Year" Type="DbType.Int32" />
 
 
 นี่เป็น List ของ DataType ใน System.Data เลือกให้ compat กันนะคะ
 
 .NET Framework Class Library
 DbType Enumeration
 Specifies the data type of a field, a property, or a Parameter object of a .NET Framework data provider.
 
 Tip นิดนึงถ้าไม่สะดวกเขียนที่ front page จะเอาไปเขียนที่ code-behind ได้ค่ะ
 ในกรณีของ update insert แล้วก็ delete นะคะ ส่วน select ควรทำที่ page aspx ค่ะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-14 15:54:52 | By :
                            blurEyes |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | พอผมเปลี่ยนค่าเป็น Type="DbType.AnsiString"
 
 มันก็ขึ้น error อย่างนี้ครับ attribute นี้ไม่สามารถใช้ได้ครับ
 Validation (ASP.Net): The values permitted for this attribute do not include 'DbType.AnsiString'
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-15 09:29:36 | By :
                            yiam21 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อันนี้มัน Auto process ค่ะพี่ตึ๋งศรี เขียนแบบ code-less พอ update ,insert หรือ delete ทั้งฐานข้อมูล และ grid จะ update กันเองเลยโดยอัตโนแม้ด เป็นวิธีขี้เกียจๆ พราวก้อใช้ยู้ว
 
 อะนะ
 Validation (ASP.Net): The values permitted for this attribute do not include 'DbType.AnsiString'
 ก็สมควรแล้วคุณไป add parameter แบบนี้นี่คะ ( ดูเผินๆ เหมือนจะถูก เง้อ เราก้อสะเพร่า )
 
 <asp:Parameter Name="@ID_Cars" Type="DbType.AnsiString" />
 ....
 <asp:Parameter Name="@Year" Type="DbType.Int32" />
 
 ต้องมี @ นำหน้าค่ะ
 
 วิธีนี้ไม่ต้องมี code behide เลยก็ได้ ทำเป็น template ก้อปๆๆๆ ก็จบแล้วค่ะ
 เสียแต่ว่าตัว gridview เวลาจะทำ edit template แบบ custom อย่าง combobox หรือ checkbox
 ออกจะลำบากๆ อยู่ค่ะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-15 11:48:02 | By :
                            blurEyes |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ตอนนี้ได้แล้วครับ ผมเข้าไปแก้ที่ Grid View ใน Inline-Code(Topicเขียนผิด ^ ^) >>>>AutoGenerateColumns="True" ให้เป็น True
 >>>>Type="String"
 
 **ขอบคุณทุกท่านนะครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-07-16 10:23:33 | By :
                            yiam21 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |