Hi, i want to add new item . The button event is fired but not the Grid1.AddedItems . Can you help me??
This is the code:
eshop.aspx code :
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="eshop.aspx.vb" Inherits="eshop" %>
<%@ Register assembly="RJS.Web.WebControl.PopCalendar" namespace="RJS.Web.WebControl" tagprefix="rjs" %>
<%@ Register TagPrefix="eo" NameSpace="EO.Web" Assembly="EO.Web" %>
<!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>ΕΠΕΞΕΡΓΑΣΙΑ </title>
<script type="text/javascript">
var g_curItemIndex = -1;
function on_begin_edit_cat(cell)
{
//Store the current item index so that we can use
//it later in on_product_change
g_curItemIndex = cell.getItemIndex();
//Get the current cell value. Unlike the previous
//sample, this sample displays "Product_Name", but
//actually stores "Product_No".
var v = cell.getValue();
//Set the drop down box's selectedIndex based on the
//current value. Each drop down item's "value" property
//contains the "Product_No".
var dropDownBox = document.getElementById("category_dropdown");
for (var i = 0; i < dropDownBox.options.length; i++)
{
if (dropDownBox.options[i].value == v)
{
dropDownBox.selectedIndex = i;
return;
}
}
//No match has been found, display the "Please Select" item
dropDownBox.selectedIndex = 0;
}
function on_end_edit_cat(cell)
{
//Get the new value from the drop down box
var dropDownBox = document.getElementById("category_dropdown");
var selectedIndex = dropDownBox.selectedIndex;
if (selectedIndex > 0)
//On dropdownlist Javascript method end_edit we get object cell
var GridItem = cell.getItem();
//Column 5 can be your hidden column to save the CountryID
var GridCell = GridItem.getCell(2);
//Set your new value that can be the
var newValue = dropDownBox.options[selectedIndex].value;
GridCell.setValue(newValue);
return dropDownBox.options[selectedIndex].text;
return null;
}
function on_begin_edit_subcat(cell)
{
g_curItemIndex = cell.getItemIndex();
var v = cell.getValue();
var dropDownBox = document.getElementById("subcategory_dropdown");
for (var i = 0; i < dropDownBox.options.length; i++)
{
if (dropDownBox.options[i].value == v)
{
dropDownBox.selectedIndex = i;
return;
}
}
dropDownBox.selectedIndex = 0;
}
function on_end_edit_subcat(cell)
{
var dropDownBox = document.getElementById("subcategory_dropdown");
var selectedIndex = dropDownBox.selectedIndex;
if (selectedIndex > 0)
//On dropdownlist Javascript method end_edit we get object cell
var GridItem = cell.getItem();
//Column 5 can be your hidden column to save the CountryID
var GridCell = GridItem.getCell(4);
//Set your new value that can be the
var newValue = dropDownBox.options[selectedIndex].value;
GridCell.setValue(newValue);
return dropDownBox.options[selectedIndex].text;
return null;
}
function on_category_change()
{
if (g_curItemIndex >= 0)
{
var grid = eo_GetObject("Grid1");
//Raises the server side ItemCommand event. The second
//parameter is not used in this sample. If you have
//multiple columns that call this function, you can use
//this second parameter to distinguish the columns. It
//can also be used to distinguish multiple actions
//from the same column
grid.raiseItemCommandEvent(g_curItemIndex, "SelectCategory");
}
}
function on_subcategory_change()
{
if (g_curItemIndex >= 0)
{
var grid = eo_GetObject("Grid1");
//Raises the server side ItemCommand event. The second
//parameter is not used in this sample. If you have
//multiple columns that call this function, you can use
//this second parameter to distinguish the columns. It
//can also be used to distinguish multiple actions
//from the same column
grid.raiseItemCommandEvent(g_curItemIndex, "SelectSubCategory");
}
}
function update_total()
{
var total = 0;
var grid = eo_GetObject("Grid1");
for (var i = 0; i < grid.getItemCount(); i++)
{
//Get the Grid item object
var item = grid.getItem(i);
//Get the item price. The price is set on the
//server side as a decimal value, not as a text,
//so no conversion is needed at here
var price = item.getCell(2).getValue();
//Get the item quantity. Note the quantity is
//entered through a textbox, which by default
//contains text value, so we need to call
//parseInt to convert it to an integer value
var quantity = item.getCell(3).getValue();
quantity = parseInt(quantity);
//Ignore this row if quantity is not a valid number
if (isNaN(quantity))
continue;
total += price * quantity;
}
//Display the total
var totalText = document.getElementById("total_text");
if (totalText)
totalText.innerHTML = total.toString();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%">
<tr>
<td style="width: 100%">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" ForeColor="#C04000"
Text="ΔΙΑΧΕΙΡΙΣΗ ΠΡΟΙΟΝΤΩΝ :" Width="352px"></asp:Label>
<asp:Label ID="LabelTeam" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 100%">
<asp:Label ID="error6" runat="server" Text="Error" Font-Names="Verdana" Font-Size="Smaller" ForeColor="#C00000" Width="944px"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" align="center" style="width: 100%">
<eo:CallbackPanel runat="server" id="CallbackPanel1" Triggers="{ControlID:Grid1;Parameter:},{ControlID:Button1;Parameter:}">
<eo:Grid id="Grid1" AllowNewItem="True" FullRowMode="False"
ColumnHeaderDividerImage="00050103" Font-Names="Tahoma" Font-Size="8.75pt" GoToBoxVisible="True"
Height="150px" ColumnHeaderAscImage="00050104" IsCallbackByMe="False" Width="930px" GridLineColor="220, 223, 228"
ColumnHeaderDescImage="00050105" GridLines="Both" BorderWidth="1px" BorderColor="#7F9DB9"
runat="server" OnItemCommand="Grid1_ItemCommand">
<ColumnHeaderStyle CssText="background-image:url('00050101');padding-left:8px;padding-top:3px;"></ColumnHeaderStyle>
<ColumnTemplates>
<eo:TextBoxColumn>
<TextBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 8.75pt; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; FONT-FAMILY: Tahoma"></TextBoxStyle>
</eo:TextBoxColumn>
<eo:DateTimeColumn>
<DatePicker DayCellHeight="16" OtherMonthDayVisible="True" SelectedDates="" TitleRightArrowImageUrl="DefaultSubMenuIcon"
DisabledDates="" TitleLeftArrowImageUrl="DefaultSubMenuIconRTL" DayHeaderFormat="FirstLetter"
ControlSkinID="None" DayCellWidth="19">
<CalendarStyle CssText="background-color: white; border-right: #7f9db9 1px solid; padding-right: 4px; border-top: #7f9db9 1px solid; padding-left: 4px; font-size: 9px; padding-bottom: 4px; border-left: #7f9db9 1px solid; padding-top: 4px; border-bottom: #7f9db9 1px solid; font-family: tahoma"></CalendarStyle>
<TitleArrowStyle CssText="cursor:hand"></TitleArrowStyle>
<PickerStyle CssText="border-bottom-color:#7f9db9;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#7f9db9;border-left-style:solid;border-left-width:1px;border-right-color:#7f9db9;border-right-style:solid;border-right-width:1px;border-top-color:#7f9db9;border-top-style:solid;border-top-width:1px;font-family:Courier New;font-size:8pt;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:1px;padding-left:2px;padding-right:2px;padding-top:2px;"></PickerStyle>
<SelectedDayStyle CssText="font-family: tahoma; font-size: 12px; background-color: #fbe694; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"></SelectedDayStyle>
<TodayStyle CssText="font-family: tahoma; font-size: 12px; border-right: #bb5503 1px solid; border-top: #bb5503 1px solid; border-left: #bb5503 1px solid; border-bottom: #bb5503 1px solid"></TodayStyle>
<MonthStyle CssText="font-family: tahoma; font-size: 12px; margin-left: 14px; cursor: hand; margin-right: 14px"></MonthStyle>
<DayHoverStyle CssText="font-family: tahoma; font-size: 12px; border-right: #fbe694 1px solid; border-top: #fbe694 1px solid; border-left: #fbe694 1px solid; border-bottom: #fbe694 1px solid"></DayHoverStyle>
<DisabledDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"></DisabledDayStyle>
<DayHeaderStyle CssText="font-family: tahoma; font-size: 12px; border-bottom: #aca899 1px solid"></DayHeaderStyle>
<OtherMonthDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"></OtherMonthDayStyle>
<DayStyle CssText="font-family: tahoma; font-size: 12px; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"></DayStyle>
<TitleStyle CssText="background-color:#9ebef5;font-family:Tahoma;font-size:12px;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;"></TitleStyle>
</DatePicker>
</eo:DateTimeColumn>
<eo:MaskedEditColumn>
<MaskedEdit ControlSkinID="None" TextBoxStyle-CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; font-family:Courier New;font-size:8pt;"></MaskedEdit>
</eo:MaskedEditColumn>
</ColumnTemplates>
<FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;"></FooterStyle>
<ContentPaneStyle CssText="border-bottom-color:#7f9db9;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#7f9db9;border-left-style:solid;border-left-width:1px;border-right-color:#7f9db9;border-right-style:solid;border-right-width:1px;border-top-color:#7f9db9;border-top-style:solid;border-top-width:1px;"></ContentPaneStyle>
<GoToBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; BORDER-TOP: #7f9db9 1px solid; BORDER-LEFT: #7f9db9 1px solid; WIDTH: 40px; BORDER-BOTTOM: #7f9db9 1px solid"></GoToBoxStyle>
<ItemStyles>
<eo:GridItemStyleSet>
<ItemHoverStyle CssText="background-color: whitesmoke"></ItemHoverStyle>
<CellStyle CssText="padding-left:8px;padding-top:2px;"></CellStyle>
<ItemStyle CssText="background-color: white"></ItemStyle>
<FixedColumnCellStyle CssText="border-right: #d6d2c2 1px solid; padding-right: 10px; border-top: #faf9f4 1px solid; border-left: #faf9f4 1px solid; border-bottom: #d6d2c2 1px solid; background-color: #ebeadb; text-align: right; color: black;"></FixedColumnCellStyle>
</eo:GridItemStyleSet>
</ItemStyles>
<Columns>
<eo:RowNumberColumn Width="40"></eo:RowNumberColumn>
<eo:CustomColumn Width="160" ClientSideEndEdit="on_end_edit_cat" ClientSideBeginEdit="on_begin_edit_cat"
HeaderText="Category">
<EditorTemplate>
<select id="category_dropdown" style="width:150px" onchange="on_category_change()">
<option>-Please Select-</option>
<asp:Repeater Runat="server" ID="Categories">
<ItemTemplate>
<option value='<%#DataBinder.Eval(Container.DataItem, "Id")%>'>
<%#DataBinder.Eval(Container.DataItem, "Titulo")%>
</option>
</ItemTemplate>
</asp:Repeater>
</select>
</EditorTemplate>
</eo:CustomColumn>
<eo:StaticColumn Width="5" HeaderText="cat"></eo:StaticColumn>
<eo:CustomColumn Width="150" ClientSideEndEdit="on_end_edit_subcat" ClientSideBeginEdit="on_begin_edit_subcat"
HeaderText="SubCategory">
<EditorTemplate>
<select id="subcategory_dropdown" style="width:150px" onchange="on_subcategory_change()">
<option>-Please Select-</option>
<asp:Repeater Runat="server" ID="SubCategories">
<ItemTemplate>
<option value='<%#DataBinder.Eval(Container.DataItem, "Id")%>'>
<%#DataBinder.Eval(Container.DataItem, "Titulo")%>
</option>
</ItemTemplate>
</asp:Repeater>
</select>
</EditorTemplate>
</eo:CustomColumn>
<eo:StaticColumn Width="5" HeaderText="subcat"></eo:StaticColumn>
<eo:TextBoxColumn Width="120" HeaderText="Name" textBoxMode="MultiLine" TextBoxRows="2" ></eo:TextBoxColumn>
<eo:TextBoxColumn Width="80" HeaderText="ProductID"></eo:TextBoxColumn>
<eo:TextBoxColumn Width="180" HeaderText="Description" textBoxMode="MultiLine" TextBoxRows="5"></eo:TextBoxColumn>
<eo:TextBoxColumn Width="50" HeaderText="Price"></eo:TextBoxColumn>
<eo:TextBoxColumn Width="50" HeaderText="Weight"></eo:TextBoxColumn>
<eo:TextBoxColumn Width="50" HeaderText="Weight ELTA"></eo:TextBoxColumn>
</Columns>
</eo:Grid>
<P>
<asp:Button id="Button1" runat="server" Text="Post Back!" OnClick="Button1_Click"></asp:Button></P>
</eo:CallbackPanel>
</P>
<p>
Total: <span id="total_text"></span>
</p>
</td>
</tr>
<tr>
<td style="width: 50%">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
______________________
eshop.aspx.vb code:
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports EO.Web.Demo
Partial Class eshop
Inherits System.Web.UI.Page
Public ukey1 As Integer
Dim pass As String
Dim alertScript As String
Dim username2 As String
Dim sSQL3 As String
Dim dv, dv3 As DataView
Public DT As DataTable
Dim ddlDataSet1, ddlDataSet2, ddlDataSet3, ddlDataSet4, ddlDataSet5, ddlDataSet As New DataSet
Dim oConn As OleDbConnection
Dim sPath As String = "xxxxxxxxxx]\store2K.mdb"
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & sPath & ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim productColumn As EO.Web.CustomColumn = CType(Grid1.Columns(1), EO.Web.CustomColumn)
Dim productRepeater As Repeater = CType(productColumn.EditorInstance.FindControl("Categories"), Repeater)
'Fill the repeater from the database
Dim db As New DemoDB()
Try
productRepeater.DataSource = db.ExecuteReader("SELECT * FROM Categories WHERE ParentID=0")
productRepeater.DataBind()
Finally
CType(db, IDisposable).Dispose()
End Try
End Sub
Protected Sub Grid1_ItemCommand(sender As Object, e As EO.Web.GridCommandEventArgs)
'The first cell contains the product number
Dim CategoryID As String = CStr(e.Item.Cells(2).Value)
Dim productColumn As EO.Web.CustomColumn = CType(Grid1.Columns(3), EO.Web.CustomColumn)
Dim productRepeater As Repeater = CType(productColumn.EditorInstance.FindControl("SubCategories"), Repeater)
Dim db As New DemoDB()
Try
'Use the product number to find out the product price
Dim sql As String = String.Format("SELECT Id, Titulo FROM Categories WHERE ParentID={0}", CategoryID)
productRepeater.DataSource = db.ExecuteReader(sql)
productRepeater.DataBind()
Finally
CType(db, IDisposable).Dispose()
End Try
End Sub 'Grid1_ItemCommand
Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
Response.Write("test")
Dim cmd As System.Data.OleDb.OleDbCommand
Dim InSql As String
oConn = New System.Data.OleDb.OleDbConnection(strConnection)
oConn.Open()
Response.Write("test2")
Dim productQty As Integer = 0
Dim item As EO.Web.GridItem
For Each item In Grid1.AddedItems
Response.Write("test3")
Try
productQty = Integer.Parse(CStr(item.Cells(6).Value))
Response.Write(productQty)
InSql = "INSERT INTO Products ( ProdID, Name, CatID ) VALUES" _
& " (@ProdID, @Name, @CatID )"
cmd = New System.Data.OleDb.OleDbCommand(InSql, oConn)
With cmd.Parameters
.Add(New OleDbParameter("@ProdID", OleDbType.Integer)).Value = Integer.Parse(CStr(item.Cells(6).Value))
.Add(New OleDbParameter("@Name", OleDbType.VarChar, 55)).Value = CStr(item.Cells(5).Value)
.Add(New OleDbParameter("@CatID", OleDbType.Integer)).Value = Integer.Parse(CStr(item.Cells(2).Value))
End With
cmd.ExecuteNonQuery()
Catch objerror As Exception
Response.Write(objerror.Message & " " & objerror.StackTrace & " " & CStr(item.Cells(6).Value))
error6.Visible = "True"
error6.Text = "ERROR-in : : " & objerror.Message & " : " & InSql
oConn.Close()
End Try
Next item
oConn.Close()
End Sub 'Button1_Click
End Class