|
Rank: Member Groups: Member
Joined: 10/4/2007 Posts: 20
|
Hi, see the follow code. If i have an empty table and i call grid.raiseItemCommandEvent(0, trigger); raise an exception. If i call grid.raiseItemCommandEvent(1, trigger); when i press same button work fine but if press another button the Grid1_ItemCommand end to work.
Code: Visual Basic.NET
Partial Class Administration_Test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid(True)
End If
End Sub
Private Function CreateTable() As DataTable
Dim DT As DataTable = New DataTable
Dim Column As DataColumn = New DataColumn("Test", GetType(String))
DT.Columns.Add(Column)
Return DT
End Function
Private Sub FillTable(ByVal DT As DataTable, ByVal Filter As Boolean)
DT.Rows.Clear()
If Not Filter Then
For Index As Integer = 1 To 10
Dim Row As DataRow = DT.NewRow
Row!Test = "Row " & Index
DT.Rows.Add(Row)
Next
End If
End Sub
Private Sub LoadGrid(ByVal Filter As Boolean)
Dim Source As DataTable = Me.CreateTable
Me.FillTable(Source, Filter)
Me.Grid1.RecordCount = Source.Rows.Count
Me.Grid1.DataSource = Source
Me.Grid1.DataBind()
End Sub
Protected Sub BtnApplyFilters_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnApplyFilters.ServerClick
ViewState("Filters") = True
End Sub
Protected Sub BtnResetFilters_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnResetFilters.Click
ViewState("Filters") = False
End Sub
Protected Sub Grid1_ItemCommand(ByVal sender As Object, ByVal e As EO.Web.GridCommandEventArgs) Handles Grid1.ItemCommand
LoadGrid(ViewState("Filters"))
End Sub
End Class
Code: HTML/ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Administration_Test" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Pagina senza titolo</title>
<script type="text/javascript">
refreshGrid = function () {
function refresh() {
var grid = eo_GetObject("Grid1");
if (grid) grid.raiseItemCommandEvent(0, "Reload");
};
window.setTimeout(refresh, 1);
};
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="5" style="width: 100%">
<tr>
<td>
<eo:CallbackPanel ID="CBPFilters" runat="server" ClientSideAfterUpdate="refreshGrid"
Triggers="{ControlID:BtnResetFilters;Parameter:},{ControlID:BtnApplyFilters;Parameter:}">
<table border="0" cellpadding="0" cellspacing="2">
<tr>
<td>
<input id="BtnApplyFilters" runat="server" class="ConfirmButton" type="button" value="Apply" /></td>
<td>
<asp:Button ID="BtnResetFilters" runat="server" CssClass="DeleteButton" Text="Reset" /></td>
</tr>
</table>
</eo:CallbackPanel>
</td>
</tr>
<tr>
<td>
<eo:Grid ID="Grid1" runat="server" AllowPaging="True" BorderColor="Gainsboro" BorderStyle="Solid"
BorderWidth="1px" ColumnHeaderAscImage="00050204" ColumnHeaderDescImage="00050205"
ColumnHeaderDividerImage="00050203" ColumnHeaderHeight="24" CssClass="EOGrid"
EnableKeyboardNavigation="True" Font-Bold="False" Font-Italic="False" Font-Names="Tahoma"
Font-Overline="False" Font-Size="8.75pt" Font-Strikeout="False" Font-Underline="False"
GridLineColor="240, 240, 240" GridLines="Both" ItemHeight="28" LoadingHTML="Attendere ..."
PagerLabelTemplate=" " RunningMode="Callback" Width="100%">
<FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" />
<ItemStyles>
<eo:GridItemStyleSet>
<ItemStyle CssText="LINE-HEIGHT: 28px; BACKGROUND-COLOR: whitesmoke" />
<AlternatingItemStyle CssText="LINE-HEIGHT: 28px; background-color:white;" />
<ItemHoverStyle CssText="background-color:aliceblue;LINE-HEIGHT: 28px; " />
<SelectedStyle CssText="background-color:aliceblue;line-height:28px;" />
<FixedColumnCellStyle CssText="" />
<CellStyle CssText="PADDING-LEFT: 8px;vertical-align:middle" />
</eo:GridItemStyleSet>
</ItemStyles>
<ColumnHeaderHoverStyle CssText="background-image:url('00050202');padding-left:8px;padding-top:4px;" />
<Columns>
<eo:StaticColumn AllowSort="True" DataField="Test" HeaderText="Test" Text="">
</eo:StaticColumn>
</Columns>
<ColumnHeaderStyle CssText="background-image:url('00050201');padding-left:8px;padding-top:4px;" />
</eo:Grid>
</td>
</tr>
</table>
</form>
</body>
</html>
Thanks YBT Seltris
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi,
The error message is normal. This is like you have an empty array and then you do array[0]. You are actually using raisesItemCommand to refresh the page, which is not the intended purpose of that function. To refresh the page, consider __doPostBack function.
I am not exactly sure what you mean by your second question. It could be related to the first one. Or related to where you place the Grid. When you update with a CallbackPanel, you should not place the Grid outside the CallbackPanel and update the Grid at the same time.
Thanks
|
|
Rank: Member Groups: Member
Joined: 10/4/2007 Posts: 20
|
I have created the callbackpanel not for grid is for a filters and must be separated by grid.. When i press "Apply" or "Reset" button it must refresh filters and them apply filters to the grid. If you try the test code you'll see that, if you set a break point in Grid1_ItemCommand function and press "Reset" the program stop in point, it work for all time you press. But if you press "Apply" the grid is clear and now if press any buttons the break point not longer works.
Example: - Set a break point into Grid1_ItemCommand - Press "Reset" button (work) - Press "Reset" button (work) - Press "Apply" button (work) - Press any button (not work)
Alternatively there is another methods (integrated in grid) different from raisesItemCommand to refresh grid??
Thanks YBT Test
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
Hi,
As mentioned in the previous post, you can not expect ItemCommand event to work when there is no item in the Grid. Your test also confirmed this: it works when there are items, it does not work when the Grid is empty. ItemCommand is based on GridItem and without a GridItem it does not work. This behavior is by design.
The Grid can be refreshed anytime when the page posts back. How and when to raises that postback would be up to you. For example, you can place a Button in the page to causes a postback. Or you can use some JavaScript to cause the postback. However you can not grab raisesItemCommandEvent, which was designed for a totally different purpose, and demand that function to do the postback for you. That function is for raising ItemCommand event and is not meant for any other purpose.
Hope this clears up.
Thanks
|
|