Hi All,
I have spent hours and days to get post back for chekbox inside a ultrawebgrid (Using Sharepoint Webpart) using updatecell event.But every time i click checkbox it making duplicate columns with no data.
No idea really what the hell is going on.
I found some wwhere that there is no way of firing an event for manually added checbox inside ultrawebgrid.
Please help me.
Million Thanks in advance.
Hello,
Your scenario is not very clear for me but I 'd suggest you take a look at the following link :
Using ItemCommand Event to Access Cell Item . The demonstrated approach is the recommended way to raise an event from control which is placed inside of Template Column of the grid.
Hi Rado,
Thanks for your response. that is little helpful.
Can you help me how to add templated checkbox column to ultrawebgrid in Sharepoint Webpart.Since webpart has no design interface , we need to do it in code behind.
Thanks.
The general way to create a Template is as follows:
1. Create class that implement ITemplate interface like this:
//Create a template
private class CustomItemTemplate : ITemplate
{
//Here you can put whatever control you want.
public void InstantiateIn(Control container)
CheckBox checkBox = new CheckBox();
checkBox.Checked = true;
container.Controls.Add(checkBox);
}
2. Create a template column then instantiate your custom template and add the template to the Column collection of the grid like this:
//Create a template column
void createTemplateColumn() {
//Create a template column.
TemplatedColumn col1 = new TemplatedColumn(true) ;
col1.Header.Caption = "Template column";
col1.Key = "r1";
//Assign the template control to the template column.
col1.CellTemplate = new CustomItemTemplate();
UltraWebGrid1.Columns.Add(col1);
Rado,
Thank you very much for your response.i used above code but i cant see the checkbox inside column.
Please help me .
Thanks
Can you post your code related to the grid please, maybe it will help to see what is going on with your code, I mean aspx and code - behind.
Thanks for quick response.
following is the code
Imports SystemImports System.DataImports System.Data.OracleClientImports Infragistics.WebUI.UltraWebGridImports System.ConfigurationImports CampAddressList.CustomItemTemplatePartial Public Class _Default Inherits System.Web.UI.Page Dim dt As New DataTable() Dim dc As DataColumn = New DataColumn("ADDRESS", Type.GetType("System.String")) Dim otDs As New DataSet Dim PIds As New StringBuilder 'collection of PID's from Dataset Protected _param As DataTable = Nothing Dim strconnection As String Dim conn As New OracleConnection Public ReadOnly Property Param() As DataTable Get Return _param End Get End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dt.Columns.Add(dc) 'Add column to to data table (dt) to get selected address
If Not Page.IsPostBack = True Then
strconnection = System.Configuration.ConfigurationManager.AppSettings("CONN") conn = New OracleConnection(strconnection)
Try
Dim ds As New DataSet Dim sString As String = " XXXXXXXXXXXXX "
conn.Open() Dim da As New OracleDataAdapter(sString, conn)
da.Fill(ds, "PRIMARY")
Me.UGrid.DataSource = ds.Tables("primary") UGrid.DataBind()
Session("Data") = ds
createTemplateColumnALL()
ClientScript.RegisterStartupScript(Me.GetType(), "javacript:HideCheckBox();", True)
conn.Close() conn.Dispose()
Catch ex As Exception lblMsg.Visible = True lblMsg.Text = ex.Message End Try End If End Sub
Private Sub createTemplateColumnALL() 'Create a template column. Dim colAll As New TemplatedColumn(True) colAll.Header.Caption = "ALL" colAll.Key = "CheckAll" 'Assign the template control to the template column. colAll.CellTemplate = New CustomItemTemplate() UGrid.Columns.Add(colAll, True) End SubEnd Class
COde in Class file:
Public Class CustomItemTemplate Implements System.Web.UI.ITemplate 'Here you can put whatever control you want. Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn Dim checkBoxAll As New CheckBox() checkBoxAll.Checked = False checkBoxAll.Visible = True checkBoxAll.AutoPostBack = True container.Controls.Add(checkBoxAll) End SubEnd Class