This article shows how you can connect to a database, get data from a database table, and display it in a DataGrid control.
Step 1: Creating a C# LINQ ASP.NET Web Site
Step 2: Adding LINQ to SQL class in App_Code in your ASP.NET Web Site
Add your database and required table in this class. After adding, the model looks like
Step 3: Creating your first ASP.NET page using LINQ
Create a new page called "linq.aspx". Within the .aspx page add a DataGrid control like so:
<asp:DataGrid ID="datagrd1" runat="server" CellPadding="4" CellSpacing="4"
Width="100%" EnableViewState="False" AutoGenerateColumns="false">
<HeaderStyle BackColor="ActiveBorder" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label runat="server" Text="User"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbluser" runat="server"
Text='<%# Eval("user") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label runat="server" Text="City"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblcity" runat="server"
Text='<%# Eval("city") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label runat="server" Text="Age"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblage" runat="server"
Text='<%# Eval("age") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Within the code-behind file we’ll then write the code for binding the datagrid like:
DataClassesDataContext dc = new DataClassesDataContext("ur_connection_string");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dc.Connection.Open();
var q = from a in dc.aaas
select new
{
user = a.user.ToString().Trim(),
city = a.city.ToString().Trim(),
age = a.age.ToString().Trim(),
};
datagrd1.DataSource = q;
datagrd1.DataBind();
}
}
compile and run the program. The result like so:
This post gives you a little idea of how
you can bind LINQ to DataSet query results, please let me know what kind of questions
you’d like to see answered, and I will do my best to answer them.
binding task schedule to data source
ReplyDeleteThanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
java training in chennai | java training in bangalore
This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
ReplyDeletepython training in chennai
python training in Bangalore
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
ReplyDeleteDevOps online Training|DevOps Training in USA
Devops Training in Chennai
Devops Training in Bangalore
I’ve desired to post about something similar to this on one of my blogs and this has given me an idea. Cool Mat.
ReplyDeleteangularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteClick here:
selenium training in chennai
selenium training in bangalore
selenium training in Pune
selenium training in pune
Selenium Online Training
https://rupeshrshinde.blogspot.com/2014/11/limitations-of-selenium-web-driver.html
Great stuff!! Keep doing and I would like to share with my friends.
ReplyDeleteSelenium Training in Chennai
Best selenium training in chennai
iOS Training in Chennai
.Net coaching centre in chennai
French Classes in Chennai
Big Data Training in Chennai
web development courses
web design training course
website designing training
I recently came across your blog and have been reading along. I thought I would leave my first comment.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
Thanks for sharing such informative guide on .Net technology. This post gives me detailed information about the .net technology. I am working as trainer in leading IT training academy offering Dot Net Training in Chennai and i use your guide to educate my students.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery