Showing posts with label Perform GridView Operation. Show all posts
Showing posts with label Perform GridView Operation. Show all posts

Friday, 21 September 2012

Perform GridView Operation

   Perform GridView Operation 




Getting perticular record in Texboxes when clicked on Gridview

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {

                //string str = e.CommandName;
                int rowi = Convert.ToInt16(e.CommandArgument);
                GridViewRow row = GridView1.Rows[rowi];
                txtNo.Text = row.Cells[0].Text;

                txtEName.Text = row.Cells[1].Text;
                txtEmail.Text = row.Cells[2].Text;
                txtTechnology.Text = row.Cells[3].Text;
            }
       }





Delete perticular Record in gridview

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int EmpId = (int)GridView1.DataKeys[e.RowIndex].Value;


            objDBEmpManager.DeleteData(EmpId);
          
               // btnSave.Text = "Deleted";
                BindGrid();
        }


          public Boolean DeleteData(int EmpID)
        {
        objSqlCommand = new SqlCommand("USP_tDMLApp_Delete",     objSqlConnection);
            objSqlCommand.CommandType = CommandType.StoredProcedure;
            objSqlCommand.Parameters.AddWithValue("EmpId", EmpID);
            objSqlConnection.Open();
            objSqlCommand.ExecuteNonQuery();
            objSqlConnection.Close();
            return true;
        }







Get gridview value 1 page to another page trough query string




<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" 
              DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID,Name,Location" 
DataNavigateUrlFormatString=
"Default2.aspx?id={0}&name={1}&loc={2}" 
Text="Transfer values to other page" />
<asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" 
                SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource>

protected void Page_Load(object sender, EventArgs e)
    {
        string strID = Request.QueryString["id"];
        string strName = Request.QueryString["name"];
        string strLocation = Request.QueryString["loc"];
        lblID.Text = strID;
        lblName.Text = strName;
        lblLocation.Text = strLocation;
}   



                      Just Logic in mini Prg.


        public string Reverse(string rev)
         {
            char[] arr = rev.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
         }
        public string SortAlfabet(string rev)
        {
            char[] arr = rev.ToCharArray();
            Array.Sort<char>(arr);
            return new string(arr);
        }
        public int Count(string no)
        {
            char[] arr = no.ToCharArray();
            int res = arr.Length;
            return res;
        }