Posts

Showing posts from May, 2021

Inserting Serial No. In Grid View Using Source Code

  Steps-  1. Select grid view. 2. Go to master tag. 3. Select edit columns. 4. Select template field. 5. Fill the header text. 6. Go to source. 7. Put the cursor in between the template field tag .  8. Here, <ItemTemplate> tag will be inserted  INSIDE <ITEMTEMPLATE> CODE FOR SERIAL NO. INSERTION IS APPLIED- <%#Container.DataItemIndex+1%>  %- it is used to read the row. #- set the serial no. +1- Insense of increment.

Grid View Event Handling

  How to create the Event inside a grid view using Link Button-  Steps-  1. Select the grid view > Edit column > select bound field [bound two column of grid view with the database table]  2. Select template field > Add some header text to it > go to source > drop down Link button > now the control will be added to your grid view. Creating 'OnClick' Event- Go to source > insert the 'onclick' Event in Link button's attribute > give any name to the Event like Send_click.  In Code Window- protected void Send_click (object sender, EventArgs e)  {   // connection open code string cs = @"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";         cn = new SqlConnection(cs);         cn.Open(); // used to activate the link button GridViewRow r1 = ((LinkButton)sender).NamingContainer as GridViewRow;  // finding the control...

Grid View Footer

To show the details at the footer like the sum of the whole amount , any text  and any formatting. Code-    string s= "select sum(amount) from Table_name;    cm =new SqlCommand(s,cn);  GridView1.FooterRow.Cells[Index].Text = cm.ExecuteReader().ToString();   GridView1.FooterRow.Cells[index].Text = "Some text you wanna print";  GridView1.FooterRow.Cells[index].ForeColor = System.Drawing.Color.Yellow;  Note- In order to do the formatting stuff with footer we need to assign the 'Show Footer' attribute to true in grid view[Go to source].    

Data Binding Functions

  Data Binding Functions are used with controls.   Eval()- - Eval function is data binding function. - It is only used with the text property of all controls excluding image control, In Image control we use this with "src". Syntax-  Text='<%# Eval("column_name")%>' // column same as database.   The column will bind to that control.  

Insert the Image in Grid View using Image Field

Image
    WE HAVE A DATABASE TABLE (ADDHAR) WITH COLUMNS (ID,NAME,ADDRESS).   Now, We have to insert the image field in the grid view-  STEPS- select the gridview > mastertag > edit columns  > select image field > set properties     File Upload Coding[Upload Button]- FileUpload1.FileName(Server.MapPath("~") + "//pics(folder_name)//" + FileUpload1.FileName ); Image1.ImageUrl = "~/pics(folder_name)/" +FileUpload1.FileName; Label1.Text = FileUpload1.FileName; Image Field-   Image field has Two major properties-  1. DataImageUrlField - Set the data base column name as same as it was given in the data base  (status)  2. DataImageUrlFormatString - Set the path of the folder where the image is stored through File upload control (pics) ~/folder_name/{0}  {0}- it symbolises the finder will start finding from beginning.  Output:- 

Aggregate Function

  Data base functions are called Aggregate Functions.   These are also called Scalar functions.  1. sum() 2. min() 3. max() 4. avg() All aggregate functions use select query. In scalar program we don't use Non-Query. Ex-  select sum(Column_name) from Table_name; Note:- column should not be empty.

Grid View Calculation

Image
  Create a table with following columns - Create a following Grid View with Bound fields and template fields with the columns and controls in it-  ""  Now , we have to code for calculate button as when we Select the desired product enter the Quantity  and click on calculate button, the respective amount of the product for no. of items will be shown in the total amount section and  the complete amount will be shown in the label .  Now,  CODE-  int qty, amt, tot, sum=0; foreach(GridViewRow gr1 in GridView1.Rows)  {  CheckBox c1 = (CheckBox) gr1.FindControl("ck1"); TextBox tq = (TextBox) gr1.Findcontrol("txtq1"); TextBox ta = (TextBox) gr1.FindControl("txta1");  if(c1.Checked) { qty = int.Parse(tq.Text);  amt = int.Parse(gr1.Cells[2].Text); tot = qty * amt;  sum = sum + tot; ta.Text = tot.ToString(); } } Label1.Text = sum.Tostring();  

CheckBox in Grid View

  Insert a CheckBox in a Grid View control-  Select the Grid View > Go to source > Put the cursor in between the Template Field > Create an Item Template tag > Put the cursor in between > Select a CheckBox from toolbox.   Delete the checked record from grid view and database- when we checked the check box then the respective record will be deleted from grid view.  CODE- { string k = @"path"; cn = new SqlConnection(k);  cn.Open(); foreach(GridViewRow gr1 in GridView1.Rows) { CheckBox c1 = (CheckBox) gr1.FindControl("txt1"); //here we find the control, create an object of it and within double quotes we give the id of checkbox.  if(c1.checked)  { string q = "delete from Table_name where roll = '"+gr1.Cells[1].Text +"' "; cm = new SqlCommand(q,cn);   cm.ExecuteNonQuery(); } } }

Grid View[Bound Field and Template Field ]

Grid view is a data control. It is used to display the records. Grid View has two properties- 1. Data Source(it always equals to dr[datareader] ) 2. Data Bind  How to insert Grid view in our project-  1. Select Grid view from toolbox (in data tools)  2. Select Grid View > Master tag   3. Select Auto format (can select the desired format)  Bound Field-  It is used to connect the database column to Grid View. Bound field has two properties- 1. Header text(give the column name which will be displayed in the grid view .. Not mandatory to give the column name as same as the data base column ) 2. Data field( Mandatory to give the name as same as database column )  How to insert bound field-  Steps-  Select grid view >Master tag >Edit columns >Select bound field >Click on add. then-  fill the data field and header text.  Note:- Unchecked the auto generate check box. How to show the data base records in Grid View- Sel...

Insert, Update and Delete_Query

INSERT- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  using System.Data.SqlClient; public partial class Registration : System.Web.UI.Page {   SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     protected void Page_Load(object sender, EventArgs e)    {     }     protected void Button1_Click(object sender, EventArgs e)  { //step 1- connection to database  string path =@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";      cn = new SqlConnection(path);      cn.Open(); //step 2- Command (write a query)         string q = " insert into Chitransh_stu values ('"+TextBox1.Text+"', '"+TextBox2.Text+"', '"+TextBox3.Text+"', )"  cm = new SqlCommand(q, cn); //step 3- execute the query...

Select Query [ Login page ]

  using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  using System.Data.SqlClient; public partial class Registration : System.Web.UI.Page {   SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     protected void Page_Load(object sender, EventArgs e)    {     protected void Button1_Click(object sender, EventArgs e)  { //step 1- connection to database  string path =@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";      cn = new SqlConnection(path);      cn.Open(); //step 2- Command (write a query)         string q = " select name, pass from Chitransh_stu where name= '"+TextBox2.Text+"' and pass = '"+TextBox6.Text+"'";  cm = new SqlCommand(q, cn);   //step 3- execute the query.   ...

Select_query[Fetching data to textbox]

  using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  using System.Data.SqlClient; public partial class Registration : System.Web.UI.Page {     SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     protected void Page_Load(object sender, EventArgs e)   {    }     protected void Button1_Click(object sender, EventArgs e)     { //step 1- connection to database         string path =@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356"  cn = new SqlConnection(path); cn.Open();         //step 2- Command (write a query)          string q = " select * from Chitransh_stu where roll= '"+TextBox1.Text+"'";  cm = new SqlCommand(q, cn);      //step 3- execute the que...

Data Base Handling [Using Code]

  using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  using System.Data.SqlClient; public partial class Registration : System.Web.UI.Page {     SqlConnection cn;     SqlCommand cm;     SqlDataReader dr;     protected void Page_Load(object sender, EventArgs e)     {     }     protected void Button1_Click(object sender, EventArgs e)     {   //step 1- connection to database         string path =@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356";         cn = new SqlConnection(path);         cn.Open();         //step 2- Command (write a query)          string q = "insert into Chitransh_stu values('" + TextBox1.Text + "' , '" + TextBox2....

DBMS Basics

  Data Base Management System- DataBase - DataBase is the collection of Entities.  Entity - Entity is the collection of Records.  Record - It is the information that a user possess [like name="Chitransh" , roll=101, age= 21 this is an information is called record]  Tuple - It is the complete record of any user.  Note: - Incomplete information will come under RECORD category but TUPLE can not be incomplete.  Field - It is representing the information(like roll, name, age)  Key -  It is a special type of field with is used to identify/ manage the complete record.  Types of Keys-   1. Primary Key.   Properties-  a) Unique(No repeat)  b) No Blank(Not Null) 2. Unique Key.  Properties- a) Unique(No repeat)  b) Blank(null)  3. Foreign Key (Referential Key) 1. It is used in Normalization. 2. Normalization is the process of reducing the complexity by dividing the master table into numerous small tabl...

MasterPage

  MasterPage is common to all the pages. ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. Master Layout/Design-  1. Header Section.  2. Navigation Bar. 3. Placeholder. 4. Footer. How to create a MasterPage-   Steps-  1. Select the root > go to new item > Select MasterPage. 2.  Delete Content Place Holder from your Master Page.  3. Go to HTML section in toolbox , Select table control.  Table controls snnipets-  a) shift+right arrow till the end of row >Modify> Merge cells. b) Continue pressing Tab [increase no. of rows] 4. Fill the header section.  5. Fill the footer section.  6. Fill the menu section. 7. Leave the placeholder section blanked.  8. Drag and drop Content Place Holder from tool box. To connect the .aspx pag...

Wizard

Sequence of an operation is called Wizard. Asp.net Wizard control is used to manage multiple forms and  collecting user input. It follows a simple mechanism that's how we can built steps, add a new step and reorder the step. How to create Wizard Server Control-  1. Select wizard control from toolbox.  2. Select MasterTag>add/remove Wizard Steps. Here we can add steps [ name them ] as forms and by selecting each step a separate page will be shown for each form and you can use the wizard. 3. We can also format the design of wizard by selecting the master Tag >Auto Format.

TEMPLATE

Image
Template is pre defined design of any website. E-COMMERCE WEBSITE FOR T-SHIRTS HOME PAGE- Collection- Exclusive- T-Shirts-  Contact-