PDA

View Full Version : [CLOSED] Repeater binding from DirectEvent



trezv
Feb 11, 2013, 8:07 PM
Hi, I've ran into two issues:
1. getting error when trying to update asp.net repeater from a directevent
2. i can't get the hyperlinks and buttons all be on the same row (and wrap if more area is needed)


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="repeater.aspx.cs" Inherits="WEB.Test.repeater" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">

ICollection CreateDataSource(string source, int size)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("id", typeof(Guid)));
dt.Columns.Add(new System.Data.DataColumn("name", typeof(String)));
for (int i = 0; i < size; i++)
{
dr = dt.NewRow();
dr[0] = Guid.NewGuid();
dr[1] = source + i.ToString();
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
r1.DataSource = CreateDataSource("pageload", 5);
r1.DataBind();
}
}

public void click(object sender, DirectEventArgs e)
{
r1.DataSource = CreateDataSource("directevent", 10);
r1.DataBind(); r1.Update();

}
</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Panel ID="Panel1" runat="server" Height="300" Title="Title">
<Content>
<asp:Repeater runat="server" ID="r1">
<ItemTemplate>

<ext:HyperLink ID="h1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' />
<ext:Button ID="btn" runat="server" Icon="Anchor" />

</ItemTemplate>
</asp:Repeater>
</Content>
</ext:Panel>
<ext:Button runat="server" Text="generate">
<DirectEvents>
<Click OnEvent="click" />
</DirectEvents>
</ext:Button>
</div>
</form>
</body>
</html>

Baidaly
Feb 12, 2013, 12:25 AM
Hello!

Try the following:


<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register Assembly="Ext.NET" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">

ICollection CreateDataSource(string source, int size)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("id", typeof(Guid)));
dt.Columns.Add(new System.Data.DataColumn("name", typeof(String)));
for (int i = 0; i < size; i++)
{
dr = dt.NewRow();
dr[0] = Guid.NewGuid();
dr[1] = source + i.ToString();
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
r1.DataSource = CreateDataSource("pageload", 5);
r1.DataBind();
}
}

public void click(object sender, DirectEventArgs e)
{
r1.DataSource = CreateDataSource("directevent", 10);
r1.DataBind();
Panel1.Render(wrap, RenderMode.AddTo);
}
</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Panel runat="server" ID="wrap" Border="false">
<Items>
<ext:Panel ID="Panel1" runat="server" Height="400" Title="Title">
<Content>
<asp:Repeater runat="server" ID="r1">
<ItemTemplate>
<ext:HyperLink ID="h1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' />
<ext:Button ID="btn" runat="server" Icon="Anchor" />
</ItemTemplate>
</asp:Repeater>
</Content>
</ext:Panel>
</Items>
</ext:Panel>

<ext:Button runat="server" Text="generate">
<DirectEvents>
<Click OnEvent="click" />
</DirectEvents>
</ext:Button>
</div>
</form>
</body>
</html>

Vladimir
Feb 12, 2013, 12:59 AM
Another solution (if you do not want to change your orignal markup)


public void click(object sender, DirectEventArgs e)
{
X.ControlsScripting = false;
r1.DataSource = CreateDataSource("directevent", 10);
r1.DataBind();
X.ControlsScripting = true;
Panel1.UpdateContent();

}

trezv
Feb 12, 2013, 6:20 PM
thank you both for your solutions! Please mark as resolved