This is a migrated thread and some comments may be shown as answers.

Convert Code from GridView to RadGrid

2 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ambu
Top achievements
Rank 1
Ambu asked on 08 Oct 2010, 08:45 PM
I was wondering is someone could give me hand converting this GridView code to work with the RadGrid control.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Get Values" OnClick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
  
public partial class _Default : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        TemplateField templateField = new TemplateField();
        GridView1.Columns.Add(templateField);
        templateField.ItemTemplate = new MyCheckBoxTemplate();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = new string[] { "a", "b", "c" };
            GridView1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
            Response.Write("RowIndex " + row.RowIndex + ": " + isChecked + "<br />");
        }
    }  
}
  
public class MyCheckBoxTemplate : ITemplate
{
    void ITemplate.InstantiateIn(Control parent)
    {
        CheckBox cb = new CheckBox();
        cb.ID = "CheckBox1";
        parent.Controls.Add(cb);
    }
}

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Oct 2010, 09:42 PM
Hello Allan,

I converted the code for you. Please download the attached file and let me know if you need further assistance.

Note that I take advantage of our advanced data-binding model.
Advanced Data-binding
Simple Data-binding

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sizo
Top achievements
Rank 1
answered on 05 Jul 2012, 10:42 AM
I am saddened at the lack of response to my post, alas I have removed it and will try other means...
Tags
Grid
Asked by
Ambu
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Sizo
Top achievements
Rank 1
Share this question
or