This is my database.

I use ADO.NET Entities Framework 3.5 to get data in my project (it is a winform application), this is my Entities:

 

I want make a grid wich has two information, name of student and class name of student,for example:

To do that, I create a class to the project and name it ItemOfGrid to make struct object of grid.

And this is code in method Form_Load of my form:

And I get a error:


But when I add command: entities.Class.ToList();

Everything is ok,the form run correctly! I don't know why? Ip anyone know why or how to fix it,please help!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: ADO.NET Entity Framework  Tags:
lequangthai posted on November 21, 2009 07:02

In this article,I will talk about how to use radio button in asp.net MVC.

To begin with open Visual Studio 2008 and choose File > New > Project > ASP.NET MVC.The first thing to do is to create a class that will be the structure of our data to fill radio button.Add new class to the project and name it RadioOption.Add the following code to the RadioOption class:

I will create a controller and name it RadioListController for this example. In the constructor of controller,following code to add data to List<RadioOption>

In method Get of action Create,following code to return a list of RadioOption to view for fill data to radio button.

In RadioListController,right click,choose Add View to genarate View of action,in the top of View,fill this code:

And following code to genarate radiobutton.

In method Post of action Create,fill this code:

"return RedirectToAction("Create", new { valueOfRadio = radio.ToString() });" to return value of radio button be selected to View of method Get of action Create to check value of radio be choose.

To do that,add this command to method Get of action Create.

ViewData["valueOfRadio"] = valueOfRadio;

This is full code of RadiolistController.cs

This is full code of View Create.aspx

Looking forward feedback from you!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: ASP.NET , ASP.NET MVC  Tags:
lequangthai posted on November 17, 2009 08:10

Bài viết này mình đọc được tại blog Suprotim Agarwal,thầy hay hay nên viết lại. Bài viết nói về việc kết hợp giữa việc ứng dụng RepeaterControl của ASP.NET và LinQ.

Mình có một Repeater Control mà mỗi dòng của nó là một radio button,mỗi dòng đó sẽ được gán với các bộ dữ liệu với nhiều cột dữ liệu,tất nhiên một trong số đó có cột Id và không thể biểu diễn giá trị cột đó trên View.Vấn đề là làm thế nào để xác định được Id của bộ dữ liệu được chọn? Một trong các cách là ta có thể sử dụng LinQ.

Chúng ta sẽ thử làm một ví dụ để biểu diễn việc này,để bắt đầu,hãy mở Visual Studio 2008,chọn File -> New -> Web -> ASP.NET Web Application.Tại đây chúng ta chủ yếu viết code trên 2 file default.aspx và default.aspx.cs

Đầu tiên,chúng ta sẽ tạo lớp People để làm cấu trúc data trong ví dụ của chúng ta.

Vì đây là ví dụ nên chúng ta sẽ tạo lớp trên trong default.aspx.cs cho tiện.

Trong class People ở trên ta sẽ sử dụng thuộc tính UniqueId làm Id cho people và tất nhiên,thuộc tính này sẽ không được hiển thị lên View. Tiếp theo,chúng ta sẽ add repeater control vào trang default.aspx.Code hoàn chỉnh:

Ở trên ta thấy có function SetUniqueRadioButton bằng javascript,sử dụng hàm này nhằm giới hạn người dùng tại một thời điểm chỉ chọn một nút radio button(một bộ dữ liệu).Thông thường,hệ thống radio button sẽ hoạt động tốt khi đặt trong cùng một GroupName (tức là tại mỗi thời điểm chỉ có thể chọn một radio button),nhưng repeater sẽ làm "hỏng" GroupName này khi được trả về trình duyệt.

Cài đặt đoạn code này vào default.aspx.cs để đảm bảo chỉ có thể chọn 1 radio button tại một thời điểm.

Tạo data để test:

tiếp theo ta sẽ viết code cho Button1_Click để tìm ra dòng dữ liệu mà ta đã được chọn,tại đây ta sẽ sử dụng LinQ

Để xác định radio button nào được chọn,mình sẽ sử dụng từ khóa "let" của LinQ, nó sẽ tạo ra một biến tạm và chỉ có câu lệnh LinQ sử dụng.

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET Webforms , LinQ  Tags:

Page List

    Calendar

    «  September 2010  »
    MoTuWeThFrSaSu
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910
    View posts in large calendar

    Recent Comments

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010 SFI.VN Team