Hi, I am mentioned in this post that how display a record in gridview from database using linq.
For this purpose you have to follow the below instruction.
First of all see my How to Insert record using linq.
Now I design the page up to textbox and button, now below that take a grid view control and design it as follow.
Your page looks like below.
Now write the code in code behind file as below.
Hope it will help you; I’m appreciate your comment and likes.
For this purpose you have to follow the below instruction.
First of all see my How to Insert record using linq.
Now I design the page up to textbox and button, now below that take a grid view control and design it as follow.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LinqSimple.aspx.cs" Inherits="LinqSimple" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"></head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:Label ID="lblname" runat="server" Text="Student Name"></asp:Label> </td> <td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox> </td> <td> <asp:Label ID="lblstd" runat="server" Text="Standard"></asp:Label> </td> <td> <asp:TextBox ID="txtstd" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="lblcnt" runat="server" Text="ContactNo"></asp:Label> </td> <td> <asp:TextBox ID="txtcnt" runat="server"></asp:TextBox> </td> <td> <asp:Label ID="lblresult" runat="server" Text="Result"></asp:Label> </td> <td> <asp:TextBox ID="txtresult" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_Click" /> </td> </tr> </table> <asp:GridView ID="gv_student" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="name" HeaderText="Student Name" /> <asp:BoundField DataField="std" HeaderText="Standard" /> <asp:BoundField DataField="cntno" HeaderText="ContactNo" /> <asp:BoundField DataField="result" HeaderText="Result" /> </Columns> </asp:GridView> </div> </form> </body> </html>
Your page looks like below.
Now write the code in code behind file as below.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class LinqSimple : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } private void BindGrid() { using (LinqDemoDataContext database = new LinqDemoDataContext()) { var slist = (from stud in database.Students select new { stud.name, stud.std, stud.cntno, stud.result }).ToList(); gv_student.DataSource = slist; gv_student.DataBind(); } } protected void btnadd_Click(object sender, EventArgs e) { using (LinqDemoDataContext database = new LinqDemoDataContext()) { Student s = new Student() { name = txtname.Text, std = txtstd.Text, cntno = Convert.ToInt32(txtcnt.Text), result = txtresult.Text }; database.Students.InsertOnSubmit(s); database.SubmitChanges(); BindGrid(); } } }Now when the page is load it display the record, and also after inserting a record it display in gridview.
Hope it will help you; I’m appreciate your comment and likes.
Hi, in this post I mentioned that how to insert using Linq in asp.net with c#. So for this purpose you have to follow instruction as below.
First of all take one LinqtoSql file,by right click on project and select addnewitem and add the SqltoLinq file give the name LinqDemo to this file, when you add it display one dialog box click on yes on that box.
Now your solution explorer looks like below, your LinqtoSql file place under App_Code folder automatically highlighted in below image.
Now in code behind file do the code as follow. In Add Button Click we insert the record in database.
First of all take one LinqtoSql file,by right click on project and select addnewitem and add the SqltoLinq file give the name LinqDemo to this file, when you add it display one dialog box click on yes on that box.
Now your solution explorer looks like below, your LinqtoSql file place under App_Code folder automatically highlighted in below image.
Now take one .aspx page and design as follow.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LinqSimple.aspx.cs" Inherits="LinqSimple" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"></head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:Label ID="lblname" runat="server" Text="Student Name"></asp:Label> </td> <td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox> </td> <td> <asp:Label ID="lblstd" runat="server" Text="Standard"></asp:Label> </td> <td> <asp:TextBox ID="txtstd" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="lblcnt" runat="server" Text="ContactNo"></asp:Label> </td> <td> <asp:TextBox ID="txtcnt" runat="server"></asp:TextBox> </td> <td> <asp:Label ID="lblresult" runat="server" Text="Result"></asp:Label> </td> <td> <asp:TextBox ID="txtresult" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_Click" /> </td> </tr> </table> </div> </form> </body> </html>
Your Page Looks like below.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class LinqSimple : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnadd_Click(object sender, EventArgs e) { using (LinqDemoDataContext database = new LinqDemoDataContext()) { Student s=new Student() { name=txtname.Text, std=txtstd.Text, cntno=Convert.ToInt32(txtcnt.Text), result=txtresult.Text }; database.Students.InsertOnSubmit(s); database.SubmitChanges(); } } }Hope it will help you.
Hi, In this post I describe that how to give alert msg on button click event using javascript.
For this I have take one Example as follow.
First of all take one .aspx form and put one text box and one button.
And then define the function Confitm() in between <head></head> tag as mention in example below.
And then call the function onClientClick event of button.
Example=>
For this I have take one Example as follow.
First of all take one .aspx form and put one text box and one button.
And then define the function Confitm() in between <head></head> tag as mention in example below.
And then call the function onClientClick event of button.
Example=>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AlerMsgUsingJavaScript.aspx.cs" Inherits="AlerMsgUsingJavaScript" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script language="javascript" type="text/javascript"> function Confirm() { var pre_qty; var pqty = document.getElementById("<%=txtbx_presentqty1.ClientID %>"); pre_qty = pqty.value; if (pre_qty != '') { return true; } else { alert('Enter Value'); return false; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtbx_presentqty1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Confirm()" /> </div> </form> </body> </html>OutPut=>
Hello, in this post you can display a alert msg using jquery when the textbox is empty.
For doing this you have to do as follow.
First take one .aspx form and then give the jquery link in between head tag.
Before giving jquey you have to put your jquery file in script folder as shown in below image.
For getting the jquery file click below link
http://blog.jquery.com/2009/02/20/jquery-1-3-2-released
Now just create a Script folder in your project and copy pate the jquery file in this folder and
give the path to script register tag you mentioned in between head tag.
Now just define the function as per define in code example as below.
After that take one textbox and one button and then onclientclick event of button call the function
as define in below example.
Example=>
For doing this you have to do as follow.
First take one .aspx form and then give the jquery link in between head tag.
Before giving jquey you have to put your jquery file in script folder as shown in below image.
For getting the jquery file click below link
http://blog.jquery.com/2009/02/20/jquery-1-3-2-released
Now just create a Script folder in your project and copy pate the jquery file in this folder and
give the path to script register tag you mentioned in between head tag.
Now just define the function as per define in code example as below.
After that take one textbox and one button and then onclientclick event of button call the function
as define in below example.
Example=>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetTextBoxValue.aspx.cs" Inherits="GetTextBoxValue" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Script/jquery-1.3.2.js"></script> <script type="text/javascript"> function btnoneclick() { if ($("input:text").val()=='') { alert('Hello how s u'); return false; } else return true; } </script> </head> <body> <form id="form1" runat="server"> <div class="bigDiv"> <asp:TextBox ID="tb6" runat="server" Text=""/> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return btnoneclick();" /> </div> </form> </body> </html>Output:-
Hi, in this post I describe that how to define the textbox keypress event using javascript in asp.net using c#.
For that you have to simple take one textbox and write the javascript function as follow.
I have give the whole design of page, in this nothing came in backend page coding.
For that you have to simple take one textbox and write the javascript function as follow.
I have give the whole design of page, in this nothing came in backend page coding.
<head> <script type = "text/javascript" > function WriteName(id) { var temp = document.getElementById('<% = Label7.ClientID %>').style.visibility = "hidden"; } function falselab(id) { var temp = document.getElementById('<% = Label4.ClientID %>').style.visibility = "hidden"; } </script> </head>In form tag below code is come.
<asp:TextBox ID="TextBox1" runat="server" onkeypress="javascript:WriteName(this);" ></asp:TextBox>
Hi, In this post i describe that how to select the particular valid date from calendar extendar user
not allow to enter invalid date.
For That you have to just use the some ajax control like following way.
before use you have to register the ajax toolkit and put the tool script manager in your code.
<asp:TextBox ID="txtbx_registrationdate" runat="server" CssClass="textbox" TabIndex="11"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtbx_registrationdate"></asp:CalendarExtender>
not allow to enter invalid date.
For That you have to just use the some ajax control like following way.
before use you have to register the ajax toolkit and put the tool script manager in your code.
<asp:TextBox ID="txtbx_registrationdate" runat="server" CssClass="textbox" TabIndex="11"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtbx_registrationdate"></asp:CalendarExtender>
Hi, In this post I mentioned that how to allow insert only numeric or float value in textbox. For doing this you have to just put the compare validate control and set the property and you work is done.
First take one text box and then take compartmentalize and set its property as follow.
<asp:TextBox ID="txtbx_issuedqty1" runat="server"></asp:TextBox>
<asp:CompareValidator ID="Cmp1" runat="server" ErrorMessage="Enter Valid Quantity" Type="Double" Operator="DataTypeCheck" ControlToValidate="txtbx_issuedqty1" ForeColor="Red" ValidationGroup="add">*</asp:CompareValidator>
Hope it will help you.