 |
 | How to implement paging in your Datagrid custom control karunakarrao | 2:09 23 Feb '05 |
|
 |
Here i wrote this event in custom class
protected override void OnPageIndexChanged(DataGridPageChangedEventArgs e) { base.CurrentPageIndex = e.NewPageIndex; base.PageSize = 5; }
|
|
|
|
 |
 | Another Implementation
| 6:50 19 Jul '04 |
|
 |
Inherit from the DataGrid and override the OnItemDataBound virtual method. Also, I put two properties in the data grid, MouseOverCssClass and MouseOutCssClass, that will allow you to set the respective css classes as design time.
public class ActiveDataGrid : System.Web.UI.WebControls.DataGrid { /// <summary> /// Css Class for the mouse over data grid row client-side event. /// </summary> [CategoryAttribute("Appearance")] public string MouseOverCssClass { get { object cssClass = this.ViewState["MouseOverCssClass"]; if (cssClass != null) { return ((string) cssClass); } return string.Empty; } set { ViewState["MouseOverCssClass"] = value; } }
/// <summary> /// Css Class for the mouse out data grid row client-side event. /// </summary> [CategoryAttribute("Appearance")] public string MouseOutCssClass { get { object cssClass = this.ViewState["MouseOutCssClass"]; if (cssClass != null) { return ((string) cssClass); } return string.Empty; } set { ViewState["MouseOutCssClass"] = value; } } protected override void OnItemDataBound(DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.className = '" + MouseOverCssClass + "';"); e.Item.Attributes.Add("onmouseout", "this.className = '" + MouseOutCssClass + "';"); } base.OnItemDataBound(e); } }
< The Code Provider />
|
|
|
|
 |
|
 |
Sorry for the extra thread.
CodeProject's servers was really slow and I posted it twice by accident.
< The Code Provider />
|
|
|
|
 |
 | Another Implementation The Code Provider | 6:18 19 Jul '04 |
|
 |
Inherit from the DataGrid and override the OnItemDataBound virtual method. Also, I put two properties in the data grid, MouseOverCssClass and MouseOutCssClass, that will allow you to set the respective css classes as design time.
public class ActiveDataGrid : System.Web.UI.WebControls.DataGrid { /// <summary> /// Css Class for the mouse over data grid row client-side event. /// </summary> [CategoryAttribute("Appearance")] public string MouseOverCssClass { get { object cssClass = this.ViewState["MouseOverCssClass"]; if (cssClass != null) { return ((string) cssClass); } return string.Empty; } set { ViewState["MouseOverCssClass"] = value; } }
/// <summary> /// Css Class for the mouse out data grid row client-side event. /// </summary> [CategoryAttribute("Appearance")] public string MouseOutCssClass { get { object cssClass = this.ViewState["MouseOutCssClass"]; if (cssClass != null) { return ((string) cssClass); } return string.Empty; } set { ViewState["MouseOutCssClass"] = value; } } protected override void OnItemDataBound(DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.className = '" + MouseOverCssClass + "';"); e.Item.Attributes.Add("onmouseout", "this.className = '" + MouseOutCssClass + "';"); } base.OnItemDataBound(e); } }
<The Code Provider />
|
|
|
|
 |
 | Seems awful complicated for such a simple task ShamusFu | 8:34 16 Jul '04 |
|
 |
Why not just use the data bound event handler and do it there?
Most data grids vary enough from each other within an app that you are writing code in the data bound event handler anyway.
Interesting encapsulation, but it seems to take a really simple concept and make it complicated. Maybe if it were part of a much more elaborate custom data grid it would be worth doing.
|
|
|
|
 |
 | Another Approach Brian Nash | 6:18 16 Jul '04 |
|
 |
Don't get me wrong, your approach is fantastic, but here's another way to skin this cat:
Add a handler for the "ItemDataBound" event
private void InitializeComponent() { this.dgGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.UserDataBind); this.Load += new System.EventHandler(this.Page_Load); }
// in the handler set up the attributes for the client side OnMouseOver and OnMouseOut Events
private void UserDataBind(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { switch ( e.Item.ItemType ) { case ListItemType.SelectedItem: case ListItemType.Item: case ListItemType.AlternatingItem: | |
|
|
 |
|
 |
On a second, more detailed, reading of the original article I see that the author encapsulated everything within a control and my "solution" didn't. You would have to put the itemboundevent handler into every page using a grid with my idea.
|
|
|
|
 |
|
 |
Thanks Brain Nash to share one of generic way of implementations of this kind of topic.
|
|
|
|
 |
 | if used two controls,how to? linhaiyuan | 20:29 27 Jun '04 |
|
 |
if used two controls,how to?
|
|
|
|
 |
 | Handle right click enjoycrack | 17:00 16 Jun '04 |
|
 |
Please help me : How to handle right click on each row in data grid? Thanx
|
|
|
|
 |
 | Enter key to work like tab key rags | 4:34 2 Jun '04 |
|
 |
Any idea how to make enter key work like tab key inside the datagrid? Thanks
|
|
|
|
 |
|
 |
public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)
{
// the following code will make the 'Enter' key function as if it were the '' key.
// if a message is sent to this object of an 'Enter' (carriage return) control key,
if (((msg.LParam == new IntPtr(1835009)) || (msg.LParam == new IntPtr(18612225))) && (msg.WParam == new IntPtr(13)))
{
// then, we want to trick or fake out the OS to believe the user had stiked the 'TAB' key.
IntPtr l = new IntPtr(983041);
msg.LParam = l;
IntPtr w = new IntPtr(9);
msg.WParam = w;
}
return base.PreProcessMessage (ref msg); // call the base proc
}
|
|
|
|
 |
 | Why separate control Bee Master | 20:47 24 May '04 |
|
 |
You can have similar mouseover effect by including following code in ItemDataBound event handler of the DataGrid. There is no need for separate control.
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'; this.style.cursor='hand';"); e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'; this.style.cursor='hand';"); }
//Start of joke Never comment ur code. If it was hard to write, it should be hard to understand !!! //End of joke
|
|
|
|
 |
 | Re: Why separate control zaf | 0:03 25 May '04 |
|
 |
Nice and consise.
Any ideas how the row can revert to either the background color (which may have been set to alternate) or to the selected row color if the mouse pointer leaves the selected row?
|
|
|
|
 |
|
 |
If you are going to use this method, then just grab the backgroundColor before changing it and put it into a temp string so you can reuse it as follows:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string strTempColor = (e.Item.ItemType == ListItemType.Item) ? ColorTranslator.ToHtml(DataGrid1.ItemStyle.BackColor) : ColorTranslator.ToHtml(DataGrid1.AlternatingItemStyle.BackColor) ; e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='powderblue'; this.style.cursor='hand';"); e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='" + strTempColor + "';"); }
There is no place like 127.0.0.1!
|
|
|
|
 |
|
 |
In my web applications I have almost a DG in every page. I am a believer than instead of writing every single time the configuration of that DG is just better to Inherit the class Datagrid and then make all the modifications. I added so much to MyDataGrid class by now that was even hard to take everything off, but the Mouse Over event, to post the article here.
Al
|
|
|
|
 |
|
 |
Thank you very much ...i am giving 5 marks to you
Sreenivasulu Palavarapu Lera Technologies, Secunderabad.
|
|
|
|
 |