This is a migrated thread and some comments may be shown as answers.

Check for zero quantity before closing page

4 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 05 Aug 2011, 11:40 AM
Hi there, im sure theres a simple fix for this but ive been wrestling with  code for too long now and im out of ideas :(

The screenshot attached shows how when the user arrives at that screen they choose a part listed by using a tickbox and then inputing the quantity required. At the moment its allowing a zero quantity to be ordered, and this causes an issue with the sql database.

I'm trying to find a way of checking before the user leaves the page (either by verification when they click the save button, or something else) to carry out a query on the tick boxes selected if the value is greater than zero. I dont want zero quantities to be allowed upon save

Ive tried following some of the example code listed on the Telerik demos, but cant find anything that verifies a line thats been selected by a tick box, and then checks that or other selected tick box lines for a zero quantity and erroring if so.

The page loads zeros as default when the page is 1st opened, which has partly caused my headache !

This is the aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="quotpart_BOM.aspx.cs" Inherits="quotpart_BOM" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<head id="Head1" runat="server">
    <title>Part Bill of material</title>
    <style type="text/css">
        #GridQuotationsPanel
        {
            height: 100%;
        }
    </style>
 
<head>
 
</head>
 
    <script language="javascript" src="../../JavaScript/PopUps.js" type="text/javascript"></script>
 
       
    </script>
 
</head>
 
 
<body>
 
    <script language="javascript" type="text/javascript">
        function Refresh() {
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
        }
 
        function RefreshAll() {
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("All");
        }
    </script>
 
    <form id="form1" runat="server">
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <div>
        <telerik:RadScriptManager ID="radScriptManager" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" EnableOutsideScripts="True" runat="server"
            OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl LoadingPanelID="loading" ControlID="GridQuotations" />
                        <telerik:AjaxUpdatedControl ControlID="txtSearchCode" />
                        <telerik:AjaxUpdatedControl ControlID="txtCode" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnSearch">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl LoadingPanelID="loading" ControlID="GridQuotations" />
                        <telerik:AjaxUpdatedControl ControlID="txtSearchCode" />
                        <telerik:AjaxUpdatedControl ControlID="txtCode" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnAdd">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl LoadingPanelID="loading" ControlID="GridQuotations" />
                        <telerik:AjaxUpdatedControl ControlID="txtSearchCode" />
                        <telerik:AjaxUpdatedControl ControlID="txtCode" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="loading" HorizontalAlign="Center" MinDisplayTime="500"
            Transparency="30" runat="server">
            <div id="divLoader" class="loading">
            </div>
        </telerik:RadAjaxLoadingPanel>
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                    <table width="100%" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="left" colspan="3">
                                <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
                                    <tr>
                                        <td valign="top" class="main-header" height="80">
                                            <table width="100%" border="0px" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td>
                                                        <table width="100%" border="0px" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td>
                                                                    <table border="0" cellspacing="0" cellpadding="0">
                                                                        <tr>
                                                                            <td class="library_logo" valign="middle">
                                                                                Library
                                                                                <asp:HiddenField ID="hdnCustomerId" runat="server" Value="0" />
                                                                                <asp:HiddenField ID="hdnQuotId" runat="server" Value="0" />
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                                <td valign="top">
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="pop_up_sub_header" valign="middle">
                                                        <table border="0" cellspacing="0" cellpadding="0" width="100%" height="27px">
                                                            <tr>
                                                                <td width="95%" class="Pdding_left">
                                                                    <asp:Label ID="lblPath" runat="server"></asp:Label>
                                                                </td>
                                                                <td>
                                                                    <a href="#" onclick="javascript:self.close();" class="close_btn">Close</a>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="popup-inner-heading2">
                                            <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                <tr>
                                                    <td align="left" width="31%">
                                                        <asp:Button ID="btnAdd" runat="server" Text="Save" class="save" OnClick="btnAdd_Click" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="popup-inner-heading2">
                                            <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                                <tr>
                                                    <td align="left" width="5%">
                                                        <span><b>Type</b></span>
                                                    </td>
                                                    <td align="left" width="15%">
                                                        <asp:DropDownList ID="ddlmode" runat="server" Width="90%">
                                                            <asp:ListItem Value="Comp">Component</asp:ListItem>
                                                            <asp:ListItem Value="Part">Parts</asp:ListItem>
                                                            <asp:ListItem Value="Prod">Product</asp:ListItem>                                                         
                                                            <asp:ListItem Value="Bought">Bought</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                    <td align="left" valign="middle" width="5%">
                                                        <asp:Button ID="btnGo" runat="server" Text="Go" class="go_button" OnClick="btnGo_Click" />
                                                    </td>
                                                    <td align="left" width="5%">
                                                        <span><b>Code</b></span>
                                                    </td>
                                                    <td align="left" width="15%">
                                                        <asp:TextBox ID="txtCode" runat="server" Width="95%"></asp:TextBox>
                                                    </td>
                                                    <td align="left" valign="middle" width="5%">
                                                        <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="../../App_Themes/GPC/images/search_search_btn.jpg"
                                                            CausesValidation="false" OnClick="btnSearch_Click" />
                                                    </td>
                                                    <td align="left" width="15%" valign="middle">
                                                        <a href="" onclick="return Overlay();">
                                                            <asp:Button ID="Button2" runat="server" CssClass="search_header" UseSubmitBehavior="false">
                                                            </asp:Button> Advanced Search</a>
                                                    </td>
                                                    <td align="left" width="10%">
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td valign="top" height="100%">
                    <div class="search_win" id='searchgrid' runat="server">
                        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td rowspan="5" class="search_slider">
                                      
                                </td>
                                <td width="17" height="25" bgcolor="#DBDBDB">
                                      
                                </td>
                                <td height="25">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td align="left" valign="middle" bgcolor="#DBDBDB">
                                                <img src="../../App_Themes/GPC/images/search_magi.jpg" width="21" height="25" />
                                            </td>
                                            <td align="right" valign="middle" bgcolor="#DBDBDB" onclick="return Closesearch();">
                                                <img src="../../App_Themes/GPC/images/search_close.jpg" onclick="return Closesearch();"
                                                    width="14" height="13" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="17" height="25" bgcolor="#DBDBDB">
                                      
                                </td>
                            </tr>
                            <tr>
                                <td width="17" height="12">
                                      
                                </td>
                                <td height="12">
                                      
                                </td>
                                <td width="17" height="12">
                                      
                                </td>
                            </tr>
                            <tr>
                                <td width="17">
                                      
                                </td>
                                <td align="center" valign="top">
                                    <asp:Panel ID="pnlSearch" runat="server" DefaultButton="Button1">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="1" align="right" valign="top">
                                                    <img src="../../App_Themes/GPC/images/search_in_left_top.jpg" width="3" height="4"
                                                        border="0" style="display: block; padding: 0; margin: 0; font-size: 0px;" />
                                                </td>
                                                <td height="4" align="left" valign="top" class="search_top_bor">
                                                </td>
                                                <td width="1" align="right" valign="top">
                                                    <img src="../../App_Themes/GPC/images/search_in_right_top.jpg" width="3" height="4"
                                                        border="0" style="display: block; padding: 0; margin: 0; font-size: 0px;" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="1" class="search_left_bor">
                                                </td>
                                                <td align="center" valign="top" bgcolor="#efefef">
                                                    <table width="90%" border="0" align="center" cellpadding="0" cellspacing="3">
                                                        <tr>
                                                            <td height="5" align="left" valign="middle">
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="middle">
                                                                <span>Code</span>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="middle">
                                                                <asp:TextBox ID="txtSearchCode" runat="server" CssClass="newinput" Type="Number"
                                                                    Width="100%" MaxLength="10" NumberFormat-DecimalDigits="0" EnableEmbeddedSkins="false">
                                                                </asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="middle">
                                                                <span>Description</span>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="middle">
                                                                <asp:TextBox ID="txtSearchDescription" runat="server" MaxLength="10" NumberFormat-DecimalDigits="0"
                                                                    CssClass="newinput" Type="Number" Width="100%" EnableEmbeddedSkins="false">
                                                                </asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="middle">
                                                                <table border="0" align="center" cellpadding="0" cellspacing="3">
                                                                    <tr>
                                                                        <td align="right">
                                                                            <asp:Button ID="Button1" runat="server" Style="display: none;" Text="Button" OnClientClick="return false;" />
                                                                            <img onclick="return Refresh();" alt="Search" src="../../App_Themes/GPC/images/search_search_btn.jpg">
                                                                        </td>
                                                                        <td align="left">
                                                                            <img onclick="return RefreshAll();" alt="View All" src="../../App_Themes/GPC/images/search_all_btn.jpg">
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                  
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                                <td width="1" class="search_right_bor">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="1">
                                                    <img src="../../App_Themes/GPC/images/search_in_left_bot.jpg" width="3" height="4"
                                                        border="0" style="display: block; padding: 0; margin: 0; font-size: 0px;" />
                                                </td>
                                                <td height="4" class="search_bot_bor">
                                                </td>
                                                <td width="1">
                                                    <img src="../../App_Themes/GPC/images/search_in_right_bot.jpg" width="3" height="4"
                                                        border="0" style="display: block; padding: 0; margin: 0; font-size: 0px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </asp:Panel>
                                </td>
                                <td width="17">
                                      
                                </td>
                            </tr>
                            <tr>
                                <td width="17">
                                      
                                </td>
                                <td>
                                      
                                </td>
                                <td width="17">
                                      
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                      
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id='maingrid' style="height: 100%;">
                        <telerik:RadGrid ID="GridQuotations" Skin="RadSkin" runat="server" Height="100%"
                            AllowPaging="True" PageSize="30" Width="100%" EnableEmbeddedSkins="False" AutoGenerateColumns="False"
                            AllowSorting="True" GridLines="None" AllowMultiRowSelection="True" EnableOutsideScripts="True"
                            OnNeedDataSource="GridQuotations_NeedDataSource">
                            <ExportSettings>
                                <Pdf PageWidth="8.5in" PageHeight="11in" PageTopMargin="" PageBottomMargin="" PageLeftMargin=""
                                    PageRightMargin="" PageHeaderMargin="" PageFooterMargin=""></Pdf>
                            </ExportSettings>
                            <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true"></PagerStyle>
                            <MasterTableView CommandItemDisplay="None" DataKeyNames="SearchID" AllowMultiColumnSorting="True"
                                AllowAutomaticUpdates="false" AllowAutomaticInserts="false" EditMode="InPlace">
 
<EditFormSettings>
<EditColumn InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif" EditImageUrl="Edit.gif" CancelImageUrl="Cancel.gif"></EditColumn>
</EditFormSettings>
 
                                <CommandItemStyle CssClass="top-icon-bar" />
                                <RowIndicatorColumn Visible="False">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Resizable="False">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridClientSelectColumn UniqueName="Column">
                                        <HeaderStyle Width="5%" />
                                    </telerik:GridClientSelectColumn>
                                    <telerik:GridTemplateColumn HeaderText="Code" UniqueName="Code" DataField="Code">
                                        <ItemTemplate>
                                            <asp:Label ID="lblCode" runat="server" Text='<%# Bind("Code") %>'></asp:Label>
                                        </ItemTemplate>
                                        <HeaderStyle Width="20%"></HeaderStyle>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Quantity" UniqueName="Quantity" DataField="Quantity">
                                        <ItemTemplate>
                                            <telerik:RadTextBox ID="txtQuantity" runat="server" Text='<%# Eval("Quantity") %>' Width="50px"></telerik:RadTextBox
                                        </ItemTemplate>
                                        <HeaderStyle Width="20%"></HeaderStyle>
                                    </telerik:GridTemplateColumn>
 
                                    <telerik:GridTemplateColumn HeaderText="Description" UniqueName="description" DataField="description">
                                        <ItemTemplate>
                                            <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("description") %>'></asp:Label
                                        </ItemTemplate>
                                        <HeaderStyle Width="25%"></HeaderStyle>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Cost(£)" UniqueName="cost">
                                        <ItemTemplate>
                                            <%# Eval("cost")%> 
                                        </ItemTemplate>
                                        <HeaderStyle Width="40%"></HeaderStyle>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                            </MasterTableView>
 
                             
                                 
                            <ClientSettings>
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                                <Selecting AllowRowSelect="true" />
                                <ClientEvents />
                            </ClientSettings>
                            <ValidationSettings CommandsToValidate="PerformInsert,Update" />
                            <ItemStyle HorizontalAlign="Left" Width="20%" />
                            <FilterMenu Skin="RadSkin" EnableEmbeddedSkins="False" EnableTheming="True">
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                            </FilterMenu>
                        </telerik:RadGrid>
                         
                    </div>
                </td>
            </tr>
            <tr>
                <td valign="bottom" class="footer-bar">
                      
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
 
</html>
 The following is the aspx.cs code

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using library.searchs;
using library.parts;
using settings.Users;
using library.Quotations;
 
public partial class quotpart_BOM : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Session["User"] != null) && ((((LoginUsers)Session["User"]).UserId > 0)))
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["cid"] != null && Request.QueryString["id"] != null)
                {
                    hdnCustomerId.Value = Request.QueryString["cid"].ToString();
                    hdnQuotId.Value = Request.QueryString["id"].ToString();
                }
            }
 
        }
        else
        {
            Response.Redirect("~/control/message.aspx?s=1");
        }
    }
    protected void GridQuotations_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        librarySearch objBLL = new librarySearch(Convert.ToInt64(hdnCustomerId.Value));
 
        //objBLL.SearchType = "Prod";
        objBLL.SearchType = ddlmode.SelectedValue;
        objBLL.Order = 2;
        objBLL.OrderBy = 1;
        objBLL.PageIndex = 1;
        objBLL.RecordperPage = 99999;
        if (txtCode.Text.Trim().Length > 0)
        {
            objBLL.Code = txtCode.Text;
            txtSearchCode.Text = txtCode.Text;
        }
        GridQuotations.DataSource = (objBLL.LibrarySearchGetAll(objBLL)).SearchResults;
        objBLL = null;
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        GridQuotations.Rebind();
    }
    protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
        GridQuotations.Rebind();
    }
    protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            txtCode.Text = txtSearchCode.Text;
            GridQuotations.MasterTableView.SortExpressions.Clear();
            GridQuotations.MasterTableView.GroupByExpressions.Clear();
            GridQuotations.Rebind();
        }
        if (e.Argument == "All")
        {
            clearSearchTerms();
            GridQuotations.MasterTableView.SortExpressions.Clear();
            GridQuotations.MasterTableView.GroupByExpressions.Clear();
            GridQuotations.Rebind();
        }
 
    }
    private void clearSearchTerms()
    {
        txtSearchCode.Text = "";
        txtSearchDescription.Text = "";
        txtCode.Text = "";
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string product_ID_STR = "";
        string product_Qty_STR = "";
        string product_type_STR = "";
        for (int i = 0; i < GridQuotations.Items.Count; i++)
        {
            if (((CheckBox)(GridQuotations.Items[i]["column"].Controls[0])).Checked)
            {
                product_ID_STR = product_ID_STR + GridQuotations.MasterTableView.DataKeyValues[i]["SearchID"].ToString() + ',';
                product_Qty_STR = product_Qty_STR + (GridQuotations.Items[i].FindControl("txtQuantity") as RadTextBox).Text + ',';
                product_type_STR = product_type_STR + (ddlmode.SelectedValue == "Prod" ? "Part" : ddlmode.SelectedValue) + ',';
            }
        }
        product_ID_STR = product_ID_STR.Trim(',');
        product_Qty_STR = product_Qty_STR.Trim(',');
        product_type_STR = product_type_STR.Trim(',');
        if (product_ID_STR.Trim().Length > 0)
        {
            QuotationBLL objQuotationBLL = new QuotationBLL();
            Quotation objQuotation = new Quotation();
            objQuotation.product_ID_STR = product_ID_STR;
            objQuotation.product_Qty_STR = product_Qty_STR;
            objQuotation.product_type_STR = product_type_STR;
            objQuotation.quot_pk = Convert.ToInt64(hdnQuotId.Value);
            objQuotation.updated_by = ((LoginUsers)Session["User"]).UserId;
            objQuotationBLL.fnAddQuotationProduct(objQuotation);
            objQuotationBLL = null;
            objQuotation = null;
            RadAjaxManager1.ResponseScripts.Add("returnToParent();");
        }
        else
        {
            RadAjaxManager1.Alert("No record selected");
        }
 
    }
}

Thanks in advance for any advice/pointers

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Aug 2011, 01:33 PM
Hello Steven,

I understand that If checkbox is checked then its quantity is greater then Zero.
and its solution is given below.

If this is not your case then elaborate your case.

Method 1 :
protected void button_click()
    {
        bool IsAllEntryGreaterThenZero = true;
        foreach (GridDataItem item in RadGrid1.SelectedItems)
        {
            TextBox txtQuantity = item.FindControl("txtQuantity") as TextBox;
            if (!string.IsNullOrEmpty(txtQuantity.Text.Trim()))
            {
                try
                {
                    if (Convert.ToInt32(txtQuantity.Text) > 0)
                    {
                        // entry is valid
                    }
                    else
                    {
                        IsAllEntryGreaterThenZero = false;
                        break;
                    }
                }
                catch
                {
                    // text not valid
                    IsAllEntryGreaterThenZero = false;
                    break;
                     
                }
            }
                else
                {
                    IsAllEntryGreaterThenZero = false;
                    break;
                    //textbox have no text
                }
        }
 
        // IsAllEntryGreaterThenZero = true ..means all checked row have quantity graeter then zero
    }

Method 2 :
protected void button_click()
    {
        bool IsAllEntryGreaterThenZero = true;
        foreach (GridDataItem item in RadGrid1.Items)
        {
            if (item.Selected)
            {
                TextBox txtQuantity = item.FindControl("txtQuantity") as TextBox;
                if (!string.IsNullOrEmpty(txtQuantity.Text.Trim()))
                {
                    try
                    {
                        if (Convert.ToInt32(txtQuantity.Text) > 0)
                        {
                            // entry is valid
                        }
                        else
                        {
                            IsAllEntryGreaterThenZero = false;
                            break;
                        }
                    }
                    catch
                    {
                        // text not valid
                        IsAllEntryGreaterThenZero = false;
                        break;
 
                    }
                }
                      else
                      {
                         IsAllEntryGreaterThenZero = false;
                         break;
                        //textbox have no text
                      }
            }
        }
 
        // IsAllEntryGreaterThenZero = true ..means all checked row have quantity graeter then zero
    }

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Steven
Top achievements
Rank 1
answered on 05 Aug 2011, 02:43 PM
Hi there and thank you for your quick response, yes you have understood my question correctly, however im having issues with the code posted. Could you please clarify in what area I should be inserting (Ive inserted it as follows)

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string product_ID_STR = "";
        string product_Qty_STR = "";
        string product_type_STR = "";
        for (int i = 0; i < GridQuotations.Items.Count; i++)
        {
            if (((CheckBox)(GridQuotations.Items[i]["column"].Controls[0])).Checked)
            {
                product_ID_STR = product_ID_STR + GridQuotations.MasterTableView.DataKeyValues[i]["SearchID"].ToString() + ',';
                product_Qty_STR = product_Qty_STR + (GridQuotations.Items[i].FindControl("txtQuantity") as RadTextBox).Text + ',';
                product_type_STR = product_type_STR + (ddlmode.SelectedValue == "Prod" ? "Part" : ddlmode.SelectedValue) + ',';
            }
        }
        product_ID_STR = product_ID_STR.Trim(',');
        product_Qty_STR = product_Qty_STR.Trim(',');
        product_type_STR = product_type_STR.Trim(',');
        if (product_ID_STR.Trim().Length > 0)
        {
            QuotationBLL objQuotationBLL = new QuotationBLL();
            Quotation objQuotation = new Quotation();
            objQuotation.product_ID_STR = product_ID_STR;
            objQuotation.product_Qty_STR = product_Qty_STR;
            objQuotation.product_type_STR = product_type_STR;
            objQuotation.quot_pk = Convert.ToInt64(hdnQuotId.Value);
            objQuotation.updated_by = ((LoginUsers)Session["User"]).UserId;
            objQuotationBLL.fnAddQuotationProduct(objQuotation);
            objQuotationBLL = null;
            objQuotation = null;
            RadAjaxManager1.ResponseScripts.Add("returnToParent();");
        }
        else
        {
            RadAjaxManager1.Alert("No record selected");
 
 
    {
        bool IsAllEntryGreaterThenZero = true;
        foreach (GridDataItem item in RadGrid.Items)
        {
            if (item.Selected)
            {
                TextBox txtQuantity = item.FindControl("txtQuantity") as TextBox;
                if (!string.IsNullOrEmpty(txtQuantity.Text.Trim()))
                {
                    try
                    {
                        if (Convert.ToInt32(txtQuantity.Text) > 0)
                        {
                            // entry is valid
                        }
                        else
                        {
                            IsAllEntryGreaterThenZero = false;
                            break;
                        }
                    }
                    catch
                    {
                        // text not valid
                        IsAllEntryGreaterThenZero = false;
                        break;
 
                    }
                }
            }
        }
 
        // IsAllEntryGreaterThenZero = true ..means all checked row have quantity graeter then zero
    }
 
        }
   // }
}
 
     
}

This is showing me the same error message on both solutions

Compiler Error Message: CS0120: An object reference is required for the non-static field, method, or property 'Telerik.Web.UI.RadGrid.SelectedItems.get'

Source Error:

Line 119:    {
Line 120:        bool IsAllEntryGreaterThenZero = true;
Line 121:        foreach (GridDataItem item in RadGrid.SelectedItems)
Line 122:        {
Line 123:            if (item.Selected)

Source File:  \Control\General\quotpart_BOM.aspx.cs    Line: 121 





Thank you again for your assistance
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Aug 2011, 06:31 AM
Hello,

To solve error : CS0120: An object reference is required for the non-static field, method, or property 'Telerik.Web.UI.RadGrid.SelectedItems.get'

foreach(GridDataItem item in GridQuotations.Items)


Please see my below code again.
protected void button_click()
   {
       bool IsAllEntryGreaterThenZero = true;
       foreach (GridDataItem item in RadGrid1.SelectedItems)
       {
           TextBox txtQuantity = item.FindControl("txtQuantity") as TextBox;
           if (!string.IsNullOrEmpty(txtQuantity.Text.Trim()))
           {
               try
               {
                   if (Convert.ToInt32(txtQuantity.Text) > 0)
                   {  
                   }
                   else
                   {
                       IsAllEntryGreaterThenZero = false;
                       break;
                   }
               }
               catch
               {  
                   IsAllEntryGreaterThenZero = false;
                   break;
               }
           }
           else
           {
               IsAllEntryGreaterThenZero = false;
               break;
           }
       }
       if (IsAllEntryGreaterThenZero)
       {
           foreach (GridDataItem item in RadGrid1.SelectedItems)
           {
               // perform your DB Opration Here               
           }
       }
   }


Thanks,
Jayesh Goyani
0
Steven
Top achievements
Rank 1
answered on 08 Aug 2011, 03:34 PM
Hi again, and thanks for your reply,

I'm still no further forwards im afraid :(

I do not get any further errors this time, but when I land on the page and tick the check box and intentionally leave the quantity as zero it still loads it as a zero quantity on the subsequent page.

Do you have any further suggestions, im pulling my hair out now :)

Thanks again !
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Steven
Top achievements
Rank 1
Share this question
or