|
DbNetGrid |
Top Previous Next |
|
DbNetGrid is a database aware grid control that is designed to create a browser based interface for database information stored in a table, view or stored procedure. It can be implemented as either a client-side object or a server-control.
Example client-side implementation code
<script>
jQuery(document).ready( init )
function init()
{
var dbnetgrid1 = new DbNetGrid("dbnetgrid1");
with (dbnetgrid1)
{
connectionString = "SamplesDatabase"
fromPart = "Suppliers"
setColumnExpressions("SupplierID","CompanyName","Address","City");
setColumnProperty("SupplierID", "label", "Supplier ID");
setColumnProperty("CompanyName",{required:true, label:"Company Name"});
setColumnProperty("Address", "editControlType", "TextArea");
bind("onRowValidate", checkSupplierName)
initialize()
}
}
///////////////////////////////////////////////////////////////
function checkSupplierName(sender, args)
///////////////////////////////////////////////////////////////
{
if (args.parameters["companyname"] == null) // Company Name not modified
return;
var sql = "select supplierid from suppliers where companyname = @companyname";
var params = {companyname : args.parameters["companyname"]};
if (sender.mode == "update")
{
sql += " and supplierid <> @supplierid";
params["supplierid"] = args.currentRecord["supplierid"];
}
if (sender.executeSingletonQuery(sql, params))
{
args.message = "A Supplier with this name is already recorded";
args.columnToHighlight = "CompanyName";
args.cancel = true;
}
}
</script>
Example server-side implementation code <DNL:DbNetGrid id="customersGrid" runat="server" ConnectionString = "SamplesDatabase" FromPart = "Suppliers" > <GridColumns> <DNL:GridColumn ColumnExpression="SupplierID" Label="Supplier ID"/> <DNL:GridColumn ColumnExpression="CompanyName" Required="true" Label="Company Name" /> <DNL:GridColumn ColumnExpression="Address" EditControlType="TextArea"/> <DNL:GridColumn ColumnExpression="City"/> </GridColumns> <GridClientEvents> <DNL:GridClientEvent EventName="onRowValidate" Handler="checkSupplierName"/> </GridClientEvents> </DNL:DbNetGrid> ...
<script>
///////////////////////////////////////////////////////////////
function checkSupplierName(sender, args)
///////////////////////////////////////////////////////////////
{
if (args.parameters["companyname"] == null) // Company Name not modified
return;
var sql = "select supplierid from suppliers where companyname = @companyname";
var params = {companyname : args.parameters["companyname"]};
if (sender.mode == "update")
{
sql += " and supplierid <> @supplierid";
params["supplierid"] = args.currentRecord["supplierid"];
}
if (sender.executeSingletonQuery(sql, params))
{
args.message = "A Supplier with this name is already recorded";
args.columnToHighlight = "CompanyName";
args.cancel = true;
}
}
</script>
|