ASP.NET - RadGrid Control  ASP.NET - RadGrid Control

Asked By Sunil Naik
19-Apr-11 01:23 AM
Hi,

      I want to use images in a radgrid column on click of a button from another normal grid.
I hav used images in radgrid item template and i want to find control of those in code behind file.
  Vickey F replied to Sunil Naik
19-Apr-11 01:27 AM
Follow this code for CRUD operation in RAD GRID-


using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Data.SqlClient; 
using Telerik.WebControls; 
using System.Configuration; 
 
public partial class _Default : System.Web.UI.Page  

    //Declare a global DataTable dtTable   
    public static DataTable dtTable; 
    //Get the connectionstring from the webconfig and declare a global SqlConnection "SqlConnection"   
    public static string connectionString = ConfigurationManager.AppSettings["ConnectionString"]; 
    public SqlConnection SqlConnection = new SqlConnection(connectionString); 
    //Declare a global SqlDataAdapter SqlDataAdapter   
    public SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(); 
    //Declare a global SqlCommand SqlCommand   
    public SqlCommand SqlCommand = new SqlCommand();   
 
    protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) 
    { 
      //Populate the Radgrid   
      dtTable = new DataTable(); 
      //Open the SqlConnection   
      SqlConnection.Open(); 
      try 
      { 
        //Select Query to populate the RadGrid with data from table Employees.   
        string selectQuery = "SELECT * FROM Employees"; 
        SqlDataAdapter.SelectCommand = new SqlCommand(selectQuery, SqlConnection); 
        SqlDataAdapter.Fill(dtTable); 
        RadGrid1.DataSource = dtTable; 
      } 
      finally 
      { 
        //Close the SqlConnection   
        SqlConnection.Close(); 
      }   
 
    } 
    protected void RadGrid1_DeleteCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
    { 
      //Get the GridDataItem of the RadGrid   
      GridDataItem item = (GridDataItem)e.Item; 
      //Get the primary key value using the DataKeyValue.   
      string EmployeeID = item.OwnerTableView.DataKeyValues[item.ItemIndex]["EmployeeID"].ToString(); 
      try 
      { 
        //Open the SqlConnection   
        SqlConnection.Open(); 
        string deleteQuery = "DELETE from Employees where EmployeeID='" + EmployeeID + "'"; 
        SqlCommand.CommandText = deleteQuery; 
        SqlCommand.Connection = SqlConnection; 
        SqlCommand.ExecuteNonQuery(); 
        //Close the SqlConnection   
        SqlConnection.Close(); 
 
      } 
      catch (Exception ex) 
      { 
        RadGrid1.Controls.Add(new LiteralControl("Unable to delete Employee. Reason: " + ex.Message)); 
        e.Canceled = true; 
      }   
 
    } 
    protected void RadGrid1_UpdateCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
    { 
      //Get the GridEditableItem of the RadGrid   
      GridEditableItem eeditedItem = e.Item as GridEditableItem; 
      //Get the primary key value using the DataKeyValue.   
      string EmployeeID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["EmployeeID"].ToString(); 
      //Access the textbox from the edit form template and store the values in string variables.   
      string LastName = (editedItem["LastName"].Controls[0] as TextBox).Text; 
      string FirstName = (editedItem["FirstName"].Controls[0] as TextBox).Text; 
      string Title = (editedItem["Title"].Controls[0] as TextBox).Text; 
      string Address = (editedItem["Address"].Controls[0] as TextBox).Text; 
      string City = (editedItem["City"].Controls[0] as TextBox).Text; 
 
      try 
      { 
        //Open the SqlConnection   
        SqlConnection.Open(); 
        //Update Query to update the Datatable  
        string updateQuery = "UPDATE Employees set LastName='" + LastName + "',FirstName='" + FirstName + "',Title='" + Title + "',Address='" + Address + "',City='" + City + "' where EmployeeID='" + EmployeeID + "'"; 
        SqlCommand.CommandText = updateQuery; 
        SqlCommand.Connection = SqlConnection; 
        SqlCommand.ExecuteNonQuery(); 
        //Close the SqlConnection   
        SqlConnection.Close(); 
 
 
      } 
      catch (Exception ex) 
      { 
        RadGrid1.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message)); 
        e.Canceled = true; 
      }   
 
    } 
    protected void RadGrid1_InsertCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
    { 
      //Get the GridEditFormInsertItem of the RadGrid   
      GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; 
 
      //string EmployeeID = (insertedItem["EmployeeID"].Controls[0] as TextBox).Text; 
 
      string LastName = (insertedItem["LastName"].Controls[0] as TextBox).Text; 
      string FirstName = (insertedItem["FirstName"].Controls[0] as TextBox).Text; 
      string Title = (insertedItem["Title"].Controls[0] as TextBox).Text; 
      string Address = (insertedItem["Address"].Controls[0] as TextBox).Text; 
      string City = (insertedItem["City"].Controls[0] as TextBox).Text; 
    
      try 
      { 
        //Open the SqlConnection   
        SqlConnection.Open(); 
        //Update Query to insert into  the database  
        string insertQuery = "INSERT into  Employees(LastName,FirstName,Title,Address,City) values('" + LastName + "','" + FirstName + "','" + Title + "','" + Address + "','" + City + "')"; 
        SqlCommand.CommandText = insertQuery; 
        SqlCommand.Connection = SqlConnection; 
        SqlCommand.ExecuteNonQuery(); 
        //Close the SqlConnection   
        SqlConnection.Close(); 
 
 
      } 
      catch (Exception ex) 
      { 
        RadGrid1.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message)); 
        e.Canceled = true; 
      }   
 
    } 
   


use this code and let me know.
  dipa ahuja replied to Sunil Naik
19-Apr-11 01:37 AM

Hi..

 

You can find the Id of Control inside RadGrid :

 

ImageButton imgBtn = (ImageButton)GridDataItem["Image"].FindControl("ImageButton1");

 

 

hope this will help you

 

  Sunil Naik replied to dipa ahuja
19-Apr-11 01:55 AM
<telerik:RadGrid ID="RadGridViewResults" runat="server" Width="100%" ShowStatusBar="true"
                    AutoGenerateColumns="False" PageSize="7" AllowSorting="True" AllowMultiRowSelection="False"
                    AllowPaging="True" OnNeedDataSource="RadGridViewResults_OnNeedDataSource" OnItemDataBound="RadGridViewResults_OnItemDataBound">
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                    <MasterTableView Width="100%" AllowMultiColumnSorting="True">
                        <Columns>
                            <telerik:GridTemplateColumn HeaderStyle-Width="1%" ItemStyle-Width="1%">
                                <ItemTemplate>
                                    <asp:Image ID="imgError" Visible="false" ToolTip="Error" runat="server" ImageUrl="../../images/Test%20Scripts/error.png" />
                                    <asp:Image ID="imgSuccess" Visible="false" ToolTip="Success" runat="server" ImageUrl="../../images/Test%20Scripts/success.png" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn SortExpression="ScriptResult" HeaderText="Script Result"
                                DataField="ScriptResult">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="UserName" HeaderText="Tested By" DataField="UserName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="LastRunOn" HeaderText="Tested On" DataField="LastRunOn">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

Im using this,now i want to find control of those images on click of a button which is used in other normal grid,and need to make those images visible on selected condition.
  Sunil Naik replied to Vickey F
19-Apr-11 01:56 AM
<telerik:RadGrid ID="RadGridViewResults" runat="server" Width="100%" ShowStatusBar="true"
                    AutoGenerateColumns="False" PageSize="7" AllowSorting="True" AllowMultiRowSelection="False"
                    AllowPaging="True" OnNeedDataSource="RadGridViewResults_OnNeedDataSource" OnItemDataBound="RadGridViewResults_OnItemDataBound">
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                    <MasterTableView Width="100%" AllowMultiColumnSorting="True">
                        <Columns>
                            <telerik:GridTemplateColumn HeaderStyle-Width="1%" ItemStyle-Width="1%">
                                <ItemTemplate>
                                    <asp:Image ID="imgError" Visible="false" ToolTip="Error" runat="server" ImageUrl="../../images/Test%20Scripts/error.png" />
                                    <asp:Image ID="imgSuccess" Visible="false" ToolTip="Success" runat="server" ImageUrl="../../images/Test%20Scripts/success.png" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn SortExpression="ScriptResult" HeaderText="Script Result"
                                DataField="ScriptResult">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="UserName" HeaderText="Tested By" DataField="UserName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="LastRunOn" HeaderText="Tested On" DataField="LastRunOn">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

Im using this,now i want to find control of those images on click of a button which is used in other normal grid,and need to make those images visible on selected condition.
Create New Account
help
provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs cant update the database from the recordset. ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database. On order to get user id = sa;workstation id = IBM-6BC8A0DACEF;packet size = 4096?; String strCom1 = ”SELECT * FROM employee”; SqlDataAdapter sqlDa1 = new SqlDataAdapter(strCom1, strCon); ds1.Tables.Add(”employee”); sqlDa1.Fill(ds1, 40, 50, ds1.Tables[”employee”].TableName connectionstring); String strCom1 = ”byroyalty”; sqlCom1 = new SqlCommand(strCom1, sqlCon1); sqlCom1.CommandType = CommandType.StoredProcedure; sqlDa1 = new SqlDataAdapter(sqlCom1); SqlParameter myPar = new SqlParameter(”@percentage”, SqlDbType.Int); sqlCom1.Parameters.Add (myPar); myPar.Value = 40 while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging enable the trace to true in the line in the html format of the page. %@ Page Language = ”vb” trace = ”true”AutoEventWireup = ”false” Codebehind = ”WebForm1.aspx.vb” Inherits = ”WebApplication2.WebForm1?&gt
adding controls to tabpages in c# using ado.net my program implements the funtionality of adding and removing the tabpages and adding the controls to the tabpages .I have three tabpages as default with the controls added to it.Now rest i addtabapges with the tabcontrols addded to it. public partial RadioButton tabRadioButton54; private System.Windows.Forms.RadioButton tabRadioButton55; private System.Windows.Forms.RadioButton tabRadioButton56; private Control control = new Control(); private System.Windows.Forms.CheckBox tab1CheckBox1; private System.Windows.Forms.CheckBox tabCheckBox2; private System.Windows RadioButton(); this.tab3RadioButton1 = new System.Windows.Forms.RadioButton(); this.tabControl1.SuspendLayout(); this.SuspendLayout(); / / / / tabControl1 / / tabPage1.Controls.Add(this.tab2CheckBox1); tabPage2.Controls.Add(this.tab1Label1); tabPage2.Controls.Add(this.tab1Button1); tabPage3.Controls.Add(this.tab3RadioButton2); tabPage3.Controls
Life Cycle Want to know about the Life cycle of ASP.net page ASP.NET 2.0 Page Life Cycle - The lifetime of an ASP.NET page is filled with events. A series of processing steps takes place during this page life cycle. Following tasks are performed: * Initialization * Instantiation of controls * Restoration & Maintainance of State * Running Event Handlers * Rendering of data to the browser The life The stages reflect the broad spectrum of tasks performed. The following stages take place 1) Page Request - This is the first stage, before the page life cycle starts. Whenever a page is requested, ASP.NET detects whether the page is to be requested, parsed and compiled
me the FAQs on Masterpages in asp.net. Thanks alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? 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. You can then create individual content pages that contain the content you want to display. When users request the content pages, they