您的位置:首页 > 其它

Dart.Powerweb.livecontrols应用

2006-06-02 18:41 225 查看

Dart.Powerweb.livecontrols是个非常不错利用javascript实现无刷新的控件集。
这个控件集的使用,大家可以参照他的帮助手册,

PowerWEB LiveControls for ASP.NET

一项Ajax技术,使用回调来访问服务器方功能,不用重载浏览器页面。无需编写JavaScript,就可以轻松创建DHTML Internet程序。

有了LiveControls,在向服务器置入数据时,Web应用程序不再闪烁……,购物车程序使用服务器方资源动态确认顾客信息、清单、物品价格、折扣等;财经软件更新汇率时不再闪动;运动软件实时更新比赛成绩……所有这一切,仅仅通过拖放ASP.NET控件即可实现(无需Java applets,Flash或JavaScript编码)。

PowerWEB LiveControls for ASP.NET含有21个Web控件,能够使用服务器方回调,更新窗体单元,无需重载整个HTML页面。该控件集可以直接取代许多标准的Microsoft控件,您可以操作客户端对象或发送数据到客户端,无需刷新页面,不打扰用户使用经历。

特性:

无需编写Java applets, Flash, JavaScript,就可以实现超级Windows效果;无需插件或ActiveX控件,就可以生成100% DHTML;
通过回调方法,无需重载页面,就可以操作大多数页面元素并在客户端进行更新;
发起服务器方回调,类似熟悉事件,无需重载页面;
双程数据传输和刷新最小化,实现高性能应用程序;
透明支持下列浏览器:IE 5.0+, IE 5 Mac, Mozilla 1.3+ (FireFox, Netscape 6+), Mozilla 1.3+ Mac (FireFox, Netscape 6+), Galeon, Konqueror,Opera 5+;
对于不支持的浏览器,降级到标准ASP.NET postback;
避免JavaScript调试,简化了代码维护工作;
单个DLL文件提供全部内置的Web控件和脚本资源;
同所有已发布的.NET Framework(1.0,1.1,2.0)版本兼容;
服务器使用DataBind()时,LiveGrid, LiveListBox, LiveDropDownList控件可以自动更新客户端;
LiveTimer控件能以任意时间间隔查询服务器;
LiveSound控件通过从服务器方调用Play()方法播放声音文件;
LiveMessageBox控件通过服务器方回调来显示警告、确认或响应消息框;
LiveTextBox控件可以引发服务器方回调,甚至在发生时捕捉热键;
LiveButton控件可以引发服务器方点击事件,点击后无需刷新就可以更新大多数控件;
LiveCallback控件可以捕捉客户端事件到服务器方回调;
控件在客户端能以批方式或非批方式工作;
其余鼠标、键盘和点击事件也可以作为服务器方回调。

1. 如果我们想将LiveControls中的数据信息,取出来转移到webcontrols上去的话,我们必须在微软的webcontrols的html里面加入“LiveControlUpdate="true"”,这样livecontrol和webcontrol就可以实现互动了。
2. 因为LiveDataGrid中没有模版列,所以要实现在LiveDataGrid中添加入webcontrol的模版列。
html 代码:
<cc1:livedatagrid id="LiveDataGrid1" style="Z-INDEX: 109; LEFT: 128px; POSITION: absolute; TOP: 200px"
runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False">
<Columns>
<cc1:LiveBoundColumn DataField="ProductID" SortExpression="ProductID" ReadOnly="True" HeaderText="ProductID"></cc1:LiveBoundColumn>
<asp:TemplateColumn SortExpression="ProductName">
<HeaderTemplate>
<b>Product Name</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "ProductName").ToString().Trim() %>' runat="server" ID="Label3"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="ProductName" runat="server" Width="100px" Text='<%# DataBinder.Eval(Container.DataItem, "ProductName") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="QuantityPerUnit">
<HeaderTemplate>
<b>Quantity PerUnit</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "QuantityPerUnit")%>' runat="server" ID="Label4"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="QuantityPerUnit" runat="server" Width="100px" Text='<%# DataBinder.Eval(Container.DataItem, "QuantityPerUnit")%>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="UnitsInStock">
<HeaderTemplate>
<b>Units In Stock</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "UnitsInStock").ToString().Trim() %>' runat="server" ID="Label5"/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="UnitsInStock" runat="server" Width="100px" Text='<%# DataBinder.Eval(Container.DataItem, "UnitsInStock").ToString().Trim() %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<cc1:LiveButtonColumn Text="Select" HeaderText="Select" CommandName="Select"></cc1:LiveButtonColumn>
<cc1:LiveEditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></cc1:LiveEditCommandColumn>
<cc1:LiveButtonColumn Text="Delete" CommandName="Delete"></cc1:LiveButtonColumn>
</Columns>
</cc1:livedatagrid>
后台代码:

if(!Page.IsPostBack)
{
this.bind("","");

Session["tt"]="";
}

private void bind(string sortField, string sortDirection)
{
string sql="select * from Products";
SqlConnection con = new SqlConnection("server=is-hezhou;uid=sa;pwd=sa;database=Northwind");

if(sortField != "")
sql+= " ORDER BY " + sortField;
if(sortField != "" && sortDirection != "")
sql+= " " + sortDirection;

SqlDataAdapter sda=new SqlDataAdapter(sql,con);
DataSet ds=new DataSet();
sda.Fill(ds);
if(ds.Tables[0].Rows.Count==0)
{
return ;
}
else
{
this.LiveDataGrid1.DataSource=ds.Tables[0].DefaultView;
this.LiveDataGrid1.DataBind();

// this.DataGrid1.DataSource=ds.Tables[0].DefaultView;
// this.DataGrid1.DataBind();

}
ds.Dispose();
ds.Clear();
sda.Dispose();
con.Close();
con.Dispose();
}
private void DoCommand(string cmdText)
{
string connectionString = "server=is-hezhou;uid=sa;pwd=sa;database=Northwind";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand(cmdText, connection);
command.ExecuteNonQuery();
connection.Close();
}
private void LiveDataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LiveDataGrid1.EditItemIndex = -1;
this.bind("","");
}

private void LiveDataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ string key = e.Item.Cells[0].Text;
DoCommand("delete Products where ProductID = " + key);
this.bind("","");
}

private void LiveDataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.LiveDataGrid1.EditItemIndex=e.Item.ItemIndex;
this.bind("","");
((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[1].FindControl("ProductName")).BorderStyle=BorderStyle.Double;
((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[2].FindControl("QuantityPerUnit")).BorderStyle=BorderStyle.Dashed;
((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[3].FindControl("UnitsInStock")).BorderStyle=BorderStyle.Dotted;
}

private void LiveDataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
LiveDataGrid1.CurrentPageIndex = e.NewPageIndex;
this.bind("", "");

}

private void LiveDataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
this.bind(e.SortExpression, "asc");
}

private void LiveDataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Get the new values from the controls
string key = e.Item.Cells[0].Text;
string prodName = ((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[1].FindControl("ProductName")).Text;
string quantity = ((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[2].FindControl("QuantityPerUnit")).Text;
string units = ((TextBox)this.LiveDataGrid1.Items[e.Item.ItemIndex].Cells[3].FindControl("UnitsInStock")).Text;

// Run the query
DoCommand("UPDATE Products Set ProductName = '" + prodName + "', QuantityPerUnit = '" + quantity + "', UnitsInStock = '" + units + "' WHERE ProductID = " + key);

// Reset the EditItemIndex
LiveDataGrid1.EditItemIndex = -1;

// Rebind the grid to display the new values
this.bind("", "");

}

private void LiveDataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="Select")
{
this.LiveTextBox1.Text=e.Item.Cells[2].Text.ToString();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: