Intersoft WebGrid Documentation
ButtonClick Event
See Also  Example Send Feedback
ISNet.WebUI.WebGrid Namespace > WebGrid Class : ButtonClick Event






Occurs when a button is clicked.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Behavior")>
<DescriptionAttribute()>
Public Event ButtonClick As ButtonClickEventHandler
Visual Basic (Usage)Copy Code
Dim instance As WebGrid
Dim handler As ButtonClickEventHandler
 
AddHandler instance.ButtonClick, handler
C# 
[CategoryAttribute("Behavior")]
[DescriptionAttribute()]
public event ButtonClickEventHandler ButtonClick
Delphi 
public event ButtonClick: ButtonClickEventHandler; 
JScript 
In JScript, you can handle the events defined by another class, but you cannot define your own.
Managed Extensions for C++ 
[CategoryAttribute("Behavior")]
[DescriptionAttribute()]
public: __event ButtonClickEventHandler* ButtonClick
C++/CLI 
[CategoryAttribute("Behavior")]
[DescriptionAttribute()]
public:
event ButtonClickEventHandler^ ButtonClick

Event Data

The event handler receives an argument of type ButtonEventArgs containing data related to this event. The following ButtonEventArgs properties provide information specific to this event.

PropertyDescription
CellValue Gets or sets the value of the specified data member binded to the column (if the button column is bound).
Column Gets or sets the column object of the button column.
ReturnValue (Inherited from ISNet.WebUI.WebGrid.BaseEventArgs)Gets or sets the return value that of the ButtonClick event
Table Gets the WebGridTable object used by the event.

Example

The following example shows you how to use ButtonClick event on the button postback mode. Note: You need to set the ColumnType to Button, and ButtonAutoPostback to True.
C#Copy Code
private void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    oleDbDataAdapter1.Fill(dsNorthWindEnt1.Customers);
    e.DataSource = dsNorthWindEnt1;
}

private void WebGrid1_ButtonClick(object sender, ISNet.WebUI.WebGrid.ButtonEventArgs e)
{
    if (e.Column.Name == "btnCol1") 
    {
       oleDbConnection1.Open();
       OleDbCommand cmd = new OleDbCommand("select count(*) from [orders] where customerid='" + e.CellValue + "'", oleDbConnection1);
       int total = int.Parse( cmd.ExecuteScalar().ToString() );
       oleDbConnection1.Close();

       WebGrid1.ClientAction.Alert("Total order for '" + e.CellValue + "' is : " + total.ToString());
    }
}
You also need to add the following javascript code on the client side:
JScriptCopy Code
<script language="javascript">
function Grid1_ButtonClick(gridId, tblName, colName, cellValue) 
{
   alert("Clicked button is : " + colName + "\nThe value is : " + cellValue);
   
   // set return false to cancel postback
   return true;
}
</script>

Remarks

When ButtonAutoPostback is set to True, the ButtonClick event will be invoked as well for both PostBackMode. You can cancel postback to occur by setting the return to false in this event (see the sample code above).

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.