Posts

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();