Thursday, February 21, 2013

Example on Gridview with CRUD operations in Asp.net


Example on Gridview with CRUD operations in Asp.net

STEP1:
Create a web project. add a web form.
 go to an .aspx page,
 for example, Default.aspx, and add an ASP.NET GridView control from toolbox.
goto gridview code
write this sample code on it.

<asp:GridView ID="gridinfo" runat="server"
 AutoGenrationColumns="False" DataKeyNmes="Id,Type"
 OnRowCancelingEdit="grid_row_cancelingedit"
 OnRowDataBound="grid_row_databound"
 OnRowEditing="grid_row_editing"
 OnRowUpdating="grid_row_update"
 OnRowCommand="grid_row_command"
 OnRowDeleting="grid_row_delete"
 ShowFooter="True">

Columns Designing:
Here we design how our Grid will display.we can place controls in the GridView also.
now see the example.

<asp:TemplateField> is used to make columns.
<ItemTemplate> is used for bind data to the control.
<EditItemTemplate> is used to put edit control in GridView
<FooterTemplate> is used to display footer control.


.........................................................................................................................


1. Editing the data in Form controls is easy instead of editing Grid controls

2. No need to apply validations again because we are already applying validations at the time of Form creation,but here w need to  apply validations again for Grid Controls
 

So lets the First method

First, Open the Default.aspx.cs page

Next,In the Page Load Bind the Grid as follows
protected void Page_Load(object sender, EventArgs e)  
    {  
       try  
        {  
SqlConnection  con = 
new SqlConnection(ConfigurationManager.ConnectionStrings["Testing"].ToString());  
            if (!Page.IsPostBack)  
            {       
                BindData();                  
            }              
        }  
        catch (Exception ex)  
        {  
            lblstatus.Text=ex.message;  
        }  
   }  
     
Next,Create a method BindData()
private void BindData()  
    {  
        try  
        {  
            if (con.State == ConnectionState.Closed)  
            {  
                con.Open();  
            }             
            SqlCommand com = new SqlCommand("select * from Testing ", con);  
            SqlDataAdapter da = new SqlDataAdapter(com);  
            DataSet ds = new DataSet();  
            da.Fill(ds, "Testing");  
            GvTesting.DataSource = ds;  
            GvTesting.DataBind();  
     }  
        catch (Exception ex)  
        {  
            lblstatus.Text = ex.Message;  
        }   
   } 
Next,Apply the Grid Editing Operation

Editing Procedure
protected void GvTesting_RowEditing(object sender, GridViewEditEventArgs e)  
    {  
        try  
        {  
            int id = Convert.ToInt32(GvTesting.DataKeys[e.NewEditIndex].Value);  
            com = new SqlCommand("select * from Testing where TestingId='" + id + "'", con);  
            SqlDataAdapter da = new SqlDataAdapter(com);  
            DataSet ds = new DataSet();  
            da.Fill(ds, "Testing");  
            if (ds.Tables["Testing"].Rows.Count != 0)  
            {  
                DataRow dr = ds.Tables["hulling"].Rows[0];  
                bindItems(dr);  
            }  
        }  
        catch (Exception ex)  
        {  
            lblstatus.Text = ex.Message;  
        }  
    }  
Write the following code to bind the data in Form controls and Hide the submit button and display the Update button

private void bindItems(DataRow dr)  
    {  
        txtName.Text = dr["Name"].ToString();          
        txtSource.Text = dr["Source"].ToString();          
        lblTestingIdId.Text = dr["TestingId"].ToString();  
         btnupdate.Visible = true;  
        btnsubmit.Visible = false;          
    }     
Next,Write the following code to update the data in database
Updating Procedure
protected void btnupdate_Click(object sender, EventArgs e)  
    {  
        try  
        {         
            com = new SqlCommand("Update Testing set Name='"+txtName.Text+"',txtSource='"+txtSource.Text+"' where lblTextingId='"+TestingId+"'",con);  
            com.ExecuteNonQuery();  
            lblstatus.Text = "Record Updated";  
            lblstatus.ForeColor = Color.Green;  
            BindData();  
            btnupdate.Visible = false;  
            btnsubmit.Visible = true;  
        }  
        catch (Exception ex)  
        {  
            lblstatus.Text = ex.Message;  
        }  
    }  
Now, write the following code to delete the record from Testing table
Deletion procedure
protected void GvTesting_RowDeleting(object sender, GridViewDeleteEventArgs e)  
    {  
        try  
        {  
            string id = GvTesting.DataKeys[e.RowIndex].Value.ToString();  
            SqlCommand cmdDelete = new SqlCommand();  
            cmdDelete.CommandText = "Delete Testing where TestingId=" + int.Parse(id);  
            cmdDelete.Connection = con;  
            if (con.State == ConnectionState.Closed)  
                con.Open();  
            cmdDelete.ExecuteNonQuery();  
            con.Close();  
            BindData();  
            lblstatus.Text = "Record Successfully Deleted";  
            lblstatus.ForeColor = Color.Red;  
        }  
        catch (Exception ex)  
        {  
            lblstatus.Text = "Falied to Delete Record";  
            lblstatus.ForeColor = Color.Red;  
        }  
    }  
Next,write the following code to set the index

protected void GvTestingRowCancelingEdit(object sender, GridViewCancelEditEventArgs e)  
    {  
        GvTesting.EditIndex = -1;  

    }    











Gridview in ASP.net

Gridview control in ASP.net
Introduction:
                 This is used to display the data in tabular format to the user.
*It provides very good  Designing ,Editing,Sorting facilities.
Drawback:
* Executing of Gridview is slow when compared with Datalist and Repeator Controls.
* It provides automatic column generation  option by this option we don't required any designing code for        
    Gridview.

Properties:
        *     Allow paging :   True/False(Default).
        *     Allow Sorting :   True/False(Default).
        *     Autogenerationcolumns :   True/False(Default).
        *    Autogenerate Delete Button :   True(Default)/False.
        *    Autogenerate Edit Button :   True(Default)/False.
        *    Columns  :   Collection.
        *    EditIndex  :   -1 (Default).
        *    PageIndex  :  0 (Default).
        *    PagerSettings
        *    Pagesize  :   10 (Default).
        *    SelectedIndex  :   -1 (Default).
        *    ShowHeader  :  True(Default)/False.
        *    ShowFooter  :  True/False(Default).
        *    ShowHeader when Empty  :  True/False(Default).

Events :
        EventName                                 ClassName                         Properties   
Pageindexchanging                              GridviewEventargs              NewpageIndex
RowcancellingEdit                               Gridview Edit Eventargs       RowIndex
RowEdiing                                          Gridview Eventargs              New Edit Index
Row Updating                                    Gridview Eventargs              RowIndex
Sorting                                               Gridview Eventargs              SortExpression     

How to read multiple tables from XML in ASP.Net

How to read XML file with multiple tables to a dataset in ASP.net

XML File:"Test.xml"


<?xml version="1.0" encoding="utf-8" ?>
<root>
<scm1>
<table>
<clm1>abc</clm1>
<clm2>1</clm2>
</table>
<table>
<clm1>xyz</clm1>
<clm2>2</clm2>
</table>
<table>
<clm1>pqr</clm1>
<clm2>3</clm2>
</table>
</scm1>
<scm2>
<table2>
<clm1>ijk</clm1>
<clm2>4</clm2>
</table2>
<table2>
<clm1>lmn</clm1>
<clm2>5</clm2>
</table2>
</scm2>
</root>

...............................................................................................................
C#:
            using System.Data;
.......................................................
       DataSet ds  = new DataSet();
                ds = new DataSet();
        ds.ReadXml(MapPath("Test.xml"));
        GridView1.DataSource = ds.Relations[0].ChildTable;
        GridView1.DataBind();
        GridView2.DataSource = ds.Relations[1].ChildTable;
        GridView2.DataBind();


Output:







Monday, February 18, 2013

AP Economy audio material in telugu for APPSC and CIVILS


I did not upload any of the clip available on this page. Just for the convenience of my viewers I kept the links here which are available freely on the Internet.

Method 1:
To download these audio material click on the link it opens a new tab and audio will play, right click on audio track and save as audio. download will start.
Method:
If that audio link navigated to Files Flash download site you just click on free download button. audio track will download.


Reference:http://www.osmanian.com

Thank you, i hope it will helpful all the best...

Indian Economy audio material in telugu for Groups,Indian Economy audio material in telugu for Civiils


Indian Economy

01  PUBLIC FINANCE

 
02  BUDJET


03  TYPES OF MONEY

04  BANKING


05  DEVELOPING CONCEPTS INSTRUCTIONS 

06  Industrial methodologies

07  Five-Year Plan

08  BHARATHA DESHA BOWGOLIKA 




I did not upload any of the clip available on this page. Just for the convenience of my visitor I kept the links here which are available freely on the Internet.

Reference:http://www.osmanian.com

Free Download all  link

Biology audio material in telugu for Groups,Biology audio material in telugu for Civils


Biology


Jeeva Shaastram-Sahaja Vanarulu (జీవశాస్త్రం-సహజవనరులు) 
Biology - natural resources  Download


Kanajaalamu (కణజాలము) 
Tissue  Download


Sookshma Jeevulu (సూక్ష్మజీవులు) 
Microbes  Download



Maanava Shareeram Aarogyam (మానవ శరీరం - ఆరోగ్యం)
The human body - Health  Download



Jeevana Vidhaanaalu (జీవన విధానాలు 1)  
Lifestyles 1  Download

Jeevana Vidhaanaalu (జీవన విధానాలు 2)
Lifestyles 2 
Download


Niyanthrana Samanvayam (నియంత్రణ సమన్వయం) 

Control and co-ordination  
Download



Prathyuthpatthi (ప్రత్యుత్పత్తి)  
 Reproduction Download


Poshana (పోషణ)  
Nurture  Download

Vyavassayam Pashu samvardhana (వ్యవసాయం-పశుసంవర్ధనము)
Agriculture -  pasusanvardhanamu  Download



Shaktimaya Prapancham (శక్తిమయ ప్రపంచం) 
Saktimaya world  Download




I did not upload any of the clip available on this page. Just for the convenience of my visitor I kept the links here which are available freely on the Internet.

Here is Free Download all  link

Reference: http://www.osmanian.com

amazon

Sukanya Samriddhi Account - SBI

SUKANYA SAMRIDDHI Account information by SBI SUKANYA SAMRIDDHI ACCOUNT : FACILITY AVAILABLE AT ALL BRANCHES OF SBI Sukanya Samriddhi ...