CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

MS SQL 2008 on ASP.NET Hosting
Free 3 Months



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 9/21/2004 7:15:03 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 84 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
1 Items, 1 Pages 1 |< << Go >> >|
lerielgaray
Asp.Net User
creating template datagrid column dynamically work just for last row9/21/2004 7:15:03 PM

0/0

could anyone see this please:

I've been building a server control that consist of a grid hierarchy
cBCDataGrid - cBCGridHighlighted - cBCGridHighlightedOnCheck

First one has standard colors, fonts,..
Second one renders java script code to highlight rows on MouseOver
Third one must render a column with a checkbox, for each row to be selected or unselected

The problem is:
Just the last row in the grid is getting such checkbox, no other previous rows get it.

The first class makes public a PreRender method in order to be able to pages using this server control to populate the grid each time with different data sources.. I'll expose main parts of the code:


**********************************************************************
cBCDataGridHighlightedOnCheck.cs
**********************************************************************

namespace WebUI.BaseControls
{
public class cBCDataGridHighlightedOnCheck: cBCDataGridHighlighted
{
protected override string generateJavaScriptCode()
{
String scriptCode = base.generateJavaScriptCode() + ....
return scriptCode;
}

protected override void CreateChildControls()
{
base.CreateChildControls();
TemplateColumn column = new TemplateColumn();

CheckBox headerCheckBox = new CheckBox();
headerCheckBox.ID = "chkAll";
headerCheckBox.AutoPostBack = false;
headerCheckBox.Attributes.Add("OnClick","javascript:SelectAllCheckboxes(this);");
column.HeaderTemplate = new DataGridTemplate(headerCheckBox);

CheckBox itemCheckBox = new CheckBox();
itemCheckBox.ID = "chkSelect";
itemCheckBox.AutoPostBack = false;
itemCheckBox.Attributes.Add("OnClick","javascript:HighlightRowOnCheck(this);");
column.ItemTemplate = new DataGridTemplate(itemCheckBox);

grid.Columns.Add(column);
}
}

public class DataGridTemplate: ITemplate
{
System.Web.UI.WebControls.WebControl fControl;

public DataGridTemplate(System.Web.UI.WebControls.WebControl acontrol)
{
fControl = acontrol;
}

public void InstantiateIn(Control container)
{
container.Controls.Add(fControl);
}
}

}


**********************************************************************
cBCDataGridHighlighted.cs
**********************************************************************

namespace WebUI.BaseControls
{
public class cBCDataGridHighlighted: cBCDataGrid
{
protected virtual string generateJavaScriptCode()
{
String scriptCode = ...
return scriptCode;
}

protected override void CreateChildControls()
{
base.CreateChildControls();
this.Controls.Add(
new LiteralControl(
"<script language='javascript'> "+
generateJavaScriptCode() +
"</script> "));
grid.ItemDataBound += new DataGridItemEventHandler(grid_ItemDataBound);
}

private void grid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ((e.Item.ItemType==ListItemType.Item) ||
(e.Item.ItemType==ListItemType.AlternatingItem))
{
e.Item.Attributes.Add("OnMouseOver","javascript:HighlightRowOnMouseOver(this)");
e.Item.Attributes.Add("OnMouseOut","javascript:HighlightRowOnMouseOut(this)");
}
}
}
}


**********************************************************************
cBCDataGrid.cs
**********************************************************************

namespace WebUI.BaseControls
{
public class cBCDataGrid : Control, INamingContainer
{
protected DataGrid grid = new DataGrid();
public event EventHandler PreRender;
protected void OnPreRender(EventArgs e)
{
PreRender(this, e);
}
private void grid_PreRender(object sender, System.EventArgs e)
{
OnPreRender(EventArgs.Empty);
}

public object DataSource
{
get
{
this.EnsureChildControls();
return ((DataGrid)Controls[0]).DataSource;
}
set
{
this.EnsureChildControls();
((DataGrid)Controls[0]).DataSource = value;
}
}

public override void DataBind()
{
((DataGrid)Controls[0]).DataBind();
}

protected override void CreateChildControls()
{
grid.ID = "fDataGrid";
grid.BackColor = Color.White;
grid.BorderColor = Color.FromName("#336666");
grid.BorderStyle = BorderStyle.Double;
grid.BorderWidth = Unit.Pixel(3);
grid.CellPadding = 4;
grid.Font.Size = FontUnit.Smaller;
grid.Font.Name = "Verdana";
grid.GridLines = GridLines.Horizontal;
grid.HorizontalAlign = HorizontalAlign.Left;
grid.Width = Unit.Percentage(100);
grid.AllowPaging = true;
grid.AllowCustomPaging = false;
grid.PagerStyle.Visible = false;
grid.PageSize = 2;
grid.SelectedItemStyle.Font.Bold = true;
grid.SelectedItemStyle.ForeColor = Color.White;
grid.SelectedItemStyle.BackColor = Color.FromName("#339966");
grid.AlternatingItemStyle.BorderColor = Color.White;
grid.ItemStyle.ForeColor = Color.FromName("#333333");
grid.HeaderStyle.Font.Bold = true;
grid.HeaderStyle.ForeColor = Color.White;
grid.HeaderStyle.BackColor = Color.FromName("#336666");
grid.FooterStyle.ForeColor = Color.FromName("#333333");
grid.FooterStyle.BackColor = Color.White;
grid.PagerStyle.Visible = false;
grid.PagerStyle.NextPageText = "next";
grid.PagerStyle.PrevPageText = "previous";
grid.PagerStyle.HorizontalAlign = HorizontalAlign.Center;
grid.PagerStyle.ForeColor = Color.White;
grid.PagerStyle.BackColor = Color.FromName("#336666");
grid.PreRender += new EventHandler(this.grid_PreRender);
this.Controls.Add(grid);
}

}
}




**********************************************************************
pruebas.aspx
**********************************************************************

namespace WebUI.Pages
{
public class pruebas : System.Web.UI.Page
{
protected WebUI.BaseControls.cBCDataGrid fDataGridHighlighted;
protected DataSet fAuxDataSet;
protected string fdbConnectionString;
protected SqlConnection fAuxConnection;
protected SqlDataAdapter fAuxDataAdapter;
protected int nRecordCount;

protected void fDataGridHighlighted_PreRender(Object sender, EventArgs e)
{
fAuxConnection = new SqlConnection(
Application["dbMelonesConnectionString"].ToString());
fAuxDataAdapter = new SqlDataAdapter();
fAuxDataAdapter.SelectCommand = new SqlCommand();
fAuxDataAdapter.SelectCommand.Connection = fAuxConnection;
fAuxDataAdapter.SelectCommand.CommandText = "sp_getlistofcharacteristics";
fAuxDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

SqlParameter ocurlanguageprefigparam = new SqlParameter ...


fAuxDataSet = new DataSet();
fAuxDataAdapter.Fill(fAuxDataSet,"tblCharacteristics");
nRecordCount = fAuxDataSet.Tables["tblCharacteristics"].Rows.Count;

fDataGridHighlighted.DataSource = fAuxDataSet;
fDataGridHighlighted.DataBind();
}

......

}


THANKS A LOT IN ADVANCE,
Leriel.


1 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:

Web:
Datagrid dynamically generated template columns dissapearing I start by creating the template columns like this: .... empty except for the very last row which contains the correct data. ...
DotNetBips.com :: Blossom your .NET skills This two part article explains just that. There are actually two ways to create DataGrid templated columns dynamically - using LoadTemplate method and ...
CodeProject: DataGrid Template Columns creation in Runtime (using ... i want code in c#, to genrate datagrid dynamically which having templet ..... I saw all controls for create Template Columns in DataGrid without Hyperlink . ...
dynamic editcommandcolumn to edit row in datagrid (i want just ... because in my datagrid columns headers and rows are dynamically added to the ... ket you can sepcify the value the datagrid column template. ...
How to use a checkbox in a datagrid template column. i have a datagrid. i'm creating template columns (check boxes) (n number) dynamically.. (Just imagine - to mark attendance of a training program - which may ...
Cutting Edge: Understanding Templates in ASP.NET This rule has just one exception regarding template-based columns. .... To create a DataGrid column dynamically, you create a new instance of the specified ...
asp.net datagrid control -- developmentnow discussions I've read that if you create dynamic columns at runtime, you have to add them during the .... How do I not show the last row in a DataGrid (for C#). ...
Scott Morrison : Defining Silverlight DataGrid Columns at Runtime There are two ways to dynamically create a template column for a DataGrid. ..... or retemplating the DataGrid to have a row frozen at the bottom used for ...
The Datagrid Revisited: Editing a Live Database in Template Columns I give the datagrid a template column and I create an edit template. .... The template will work with the single row dataset, which contains fields which ...
Index of last row in datagrid [Archive] - CodingForums.com I have a datagrid where I have a template column. ... How can I get the EditItemIndex of the last row thus allowing me to use paging? ...




Search This Site:










adding setup forms in web deployment project

failed to access iis metabase

wdp 2008 pre-rtw trial

missing project references

merged dlls not being deleted after-the-fact

deployment project has compile warnings for propertygroup children

web deployment project and web application project

aspnetcompiler 1

capture existing config settings during a site upgrade

my web site does not work with normal url

how to generate dll file without using web deployment project

is it possible???

web services

a strange error when deploying precompiled dll not updateable using wdp

wdp command line

desired: separate version #s for single page generated dlls in web deployment project

web deployment project only copies files of 'known' extension??

update application option in windows installer

the app_globalresources folder is missing in the web setup project

how to deploy

sometimes a new web page gets a designer.cs file when it's created and sometimes it does not...

the installer was interrupted before xx

deployment asp.net 2.0

assembly code access problem on 1and1 server

deploying created web pages to sharepoint

source code issue in deployment

deploy selective folders from user interface checkbox screen

retrieving the com class factory.....

custom action

installing a web project

  Privacy | Contact Us
All Times Are GMT