Hi,
I am binding a radgrid runtime using GridTemplateColumns. In my grid the first 3 columns should be freezed, and from other columns, some contains just lables, and some with radnumerictexboxes.
I've created columns using GridTemplateColumn successfully, but confused with assigning data to the grid. I need to give each lable and numerictextbox a different id, so that i can get the data from it to save in database.
So that is my first question..
1) How can I bind data with different IDs to each control in grid.
2) How can I freeze columns? If i bind grid using SqlDataSource, freezing works perfect, but when it bind it using GridTemplateColumns and all, freezing does not work.
Here is a sample code, please correct me where I am wrong:
I've to submit this by tomorrow, please reply whoever knows solution ASAP.
Thanks.
I am binding a radgrid runtime using GridTemplateColumns. In my grid the first 3 columns should be freezed, and from other columns, some contains just lables, and some with radnumerictexboxes.
I've created columns using GridTemplateColumn successfully, but confused with assigning data to the grid. I need to give each lable and numerictextbox a different id, so that i can get the data from it to save in database.
So that is my first question..
1) How can I bind data with different IDs to each control in grid.
2) How can I freeze columns? If i bind grid using SqlDataSource, freezing works perfect, but when it bind it using GridTemplateColumns and all, freezing does not work.
Here is a sample code, please correct me where I am wrong:
<rad:RadGrid ID="radTestInputs" Width="100px" EnableAJAX="True" AutoGenerateColumns="false" EnableAJAXLoadingTemplate="True" GridLines="None" AllowSorting="True" AllowPaging="True" runat="server" Skin="WinXP"> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"> <Resizing AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="True" FrozenColumnsCount="1" /> </ClientSettings> <HeaderStyle Width="100px" /> </rad:RadGrid> Partial Class DefaultVB Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindGrid() End If End Sub Public Sub BindGrid() Dim templateColumnName As String = "Number" Dim templateColumn As New GridTemplateColumn() templateColumn.ItemTemplate = New MyTemplateCaption("Number") templateColumn.HeaderText = templateColumnName templateColumn.ItemStyle.Width = Unit.Pixel(80) templateColumn.HeaderStyle.Width = Unit.Pixel(80) templateColumn.DataField = "Number" radTestInputs.MasterTableView.Columns.Add(templateColumn) Dim templateColumnName1 As String = "Test" Dim templateColumn1 As New GridTemplateColumn() templateColumn1.ItemTemplate = New MyTemplateCaption("Test") templateColumn1.HeaderText = templateColumnName1 templateColumn1.ItemStyle.Width = Unit.Pixel(80) templateColumn1.HeaderStyle.Width = Unit.Pixel(80) templateColumn1.DataField = "Test" radTestInputs.MasterTableView.Columns.Add(templateColumn1) Dim dt As DataTable = New DataTable() dt.Columns.Add("Number") dt.Columns.Add("Test") Dim dr As DataRow = dt.NewRow() dr(0) = "1" dr(1) = "Test1" dt.Rows.Add(dr) Dim dr1 As DataRow = dt.NewRow() dr1(0) = "2" dr1(1) = "Test2" dt.Rows.Add(dr1) radTestInputs.DataSource = dt radTestInputs.DataBind() End SubEnd ClassClass MyTemplateCaption Implements ITemplate Protected lControl As LiteralControl Private value As String, id As String Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) _ Implements System.Web.UI.ITemplate.InstantiateIn lControl = New LiteralControl() lControl.ID = value 'How can I provide different id for each control here? AddHandler lControl.DataBinding, AddressOf label1_DataBinding container.Controls.Add(lControl) End Sub Public Sub New(ByVal cValue As String) value = cValue End Sub Private Sub label1_DataBinding(ByVal sender As Object, ByVal e As EventArgs) Dim target As LiteralControl = DirectCast(sender, LiteralControl) Dim item As GridDataItem = DirectCast(target.BindingContainer, GridDataItem) Dim row As DataRowView = DirectCast(item.DataItem, DataRowView) If (target.ID.ToLower().Contains("number")) Then 'Not proper- here I Need to assign text according to the control's id target.Text = row.Item(0).ToString() Else target.Text = row.Item(1).ToString() End If End SubEnd ClassI've to submit this by tomorrow, please reply whoever knows solution ASAP.
Thanks.