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

dynamic row in radgrid

2 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali Uğur
Top achievements
Rank 1
Ali Uğur asked on 18 Mar 2010, 11:20 AM
Hi there,

I have a radgrid which is created dynamically in C#. Now I want to add a new dynamic row which should be different in every row. I have managed adding a new link coloumn, however it seems same in every row.

Here is the code;

        public void Gridi_Getir() 
        { 
            DataSet musteriDataSet = new DataSet(); 
            musteriDataSet = bllMusteri.MusteriGetir(); 
            DataView musteriDataView = musteriDataSet.Tables["Musteriler"].DefaultView; 
            RadGrid1.DataSource = musteriDataView; 
             
            for (int i = 0; i < musteriDataView.Count; i++) 
            { 
                dtoMusteri musteri = new dtoMusteri(); 
                musteri.MusteriID = Convert.ToInt32(musteriDataView[i].Row.ItemArray[0]);  
                HesapKartlariniGetir(musteri, i); 
            } 
 
            RadGrid1.DataBind(); 
        } 
 
        public void HesapKartlariniGetir(dtoMusteri musteri, int k) 
        { 
            ArrayList hesapKartlari = bllMusteriHesapKarti.MusteriIDyeGoreMusteriHesapKartiGetir(musteri.MusteriID); 
 
            for (int i = 0; i < hesapKartlari.Count; i++) 
            { 
                //TableCell cell = new TableCell(); 
 
                //cell.Text = ((CoalSoft.DTO.dtoMusteriHesapKarti)(hesapKartlari[i])).MusteriHesapKartiAdi; 
 
                GridHyperLinkColumn column = new GridHyperLinkColumn(); 
                //column.InitializeCell(cell, i, RadGrid1.Items[k]); 
                column.ItemStyle.Font.Name = "Tahoma"
                column.Text = ((CoalSoft.DTO.dtoMusteriHesapKarti)(hesapKartlari[i])).MusteriHesapKartiAdi; 
                column.NavigateUrl = "MusteriHesapKartiDetay.aspx?MusteriHesapKartID=" + ((CoalSoft.DTO.dtoMusteriHesapKarti)(hesapKartlari[i])).MusteriHesapKartiID; 
 
                RadGrid1.Columns.Insert(i + 4, column); 
            } 
        } 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Ali Uğur
Top achievements
Rank 1
answered on 19 Mar 2010, 09:31 AM
Any ideas?
0
Veli
Telerik team
answered on 23 Mar 2010, 12:30 PM
Hello Ali,

You can add a GridTemplateColumn to your grid and initialize a customizable ITemplate object for the ItemTemplate of the column. Using the DataBinding event of the controls in the template, you can get a reference to the GridDataItem instance for which the template is initialized. There, you can customize your controls as much as you need based on item data values:

public class MyGridTemplateColumnTemplate : ITemplate
{
    #region ITemplate Members
 
    public void InstantiateIn(Control container)
    {
        TextBox textBox = new TextBox();
        textBox.ID = "TextBox1";
        textBox.DataBinding += new EventHandler(textBox_DataBinding);
        container.Controls.Add(textBox);
    }
 
    void textBox_DataBinding(object sender, EventArgs e)
    {
        TextBox textBox = (TextBox)sender;
        GridDataItem item = (GridDataItem)item.NamingContainer;
        int itemId = (int)DataBinder.Eval(item.DataItem, "ID");
        //In this way, you can access data values and customize
        //the control firing DataBinding event for each cell
    }
 
    #endregion
}

This is the general approach in customizing databound controls in template columns. If you give us some more details on what exactly is your scenario and what you need to implement, we might be able to suggest a more specific approach.

Greetings,
Veli
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.
Tags
Grid
Asked by
Ali Uğur
Top achievements
Rank 1
Answers by
Ali Uğur
Top achievements
Rank 1
Veli
Telerik team
Share this question
or