I've got a User Control "SelectBatchByTerminal", that has two dropdown lists, "TerminalDropDownList" and "BatchDropDownList".
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class UserControls_SelectBatchByTerminal : System.Web.UI.UserControl
- {
- public delegate void BatchChangedDelegate(Int32 Batch);
- public event BatchChangedDelegate OnBatchChanged;
- public Int32 Batch
- {
- get
- {
- if (BatchDropDownList.Items.Count == 0)
- return 0;
- if (BatchDropDownList.SelectedValue == null)
- return 0;
- if (BatchDropDownList.SelectedIndex == 0)
- return 0;
- return Convert.ToInt32(BatchDropDownList.SelectedValue);
- }
- }
- public string SelectedTerminalID
- {
- get
- {
- if ((TerminalDropDownList.Items.Count == 0) || (TerminalDropDownList.SelectedIndex == 0))
- return "";
- return TerminalDropDownList.SelectedValue;
- }
- }
- public string SelectedBatch
- {
- get
- {
- if ((BatchDropDownList.Items.Count == 0) || (BatchDropDownList.SelectedIndex == 0))
- return "";
- return BatchDropDownList.SelectedValue;
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- BindTerminals();
- }
- protected void BindTerminals()
- {
- Trace.Write("Binding Data");
- TerminalDropDownList.DataTextField = DAL.CashTrack.Terminals.Columns.TerminalId;
- TerminalDropDownList.DataValueField = DAL.CashTrack.Terminals.Columns.TerminalId;
- //Line below to be re-written to use SelectedTerminalId instead of LoggedInUser
- TerminalDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetTerminalForBatch(Global.LoggedInUser.FkBanksID.Value).GetDataSet();
- TerminalDropDownList.DataBind();
- TerminalDropDownList.Items.Insert(0, new ListItem(">> Select <<", "0"));
- TerminalDropDownList.SelectedIndex = 0;
- }
- protected void BindBatches(string terminal)
- {
- BatchDropDownList.DataTextField = DAL.CashTrack.Deposits.Columns.Batch;
- BatchDropDownList.DataValueField = DAL.CashTrack.Deposits.Columns.Batch;
- BatchDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetBatchByTerminal(terminal).GetDataSet();
- BatchDropDownList.DataBind();
- BatchDropDownList.Items.Insert(0, new ListItem(">> Select <<", "0"));
- BatchDropDownList.SelectedIndex = 0;
- }
- protected void TerminalDropDownList_SelectedIndexChanged(object sender, EventArgs e)
- {
- BindBatches(TerminalDropDownList.SelectedValue);
- }
- protected void BatchDropDownList_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.Batch != 0)
- {
- if (OnBatchChanged != null)
- OnBatchChanged(this.Batch);
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class Deposits_DepositPerBatch : System.Web.UI.Page
- {
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- wiz.ActiveStepIndex = 0;
- SelectBatchByTerminalUC.OnBatchChanged += new UserControls_SelectBatchByTerminal.BatchChangedDelegate(OnBatchChanged);
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void OnBatchChanged(Int32 Batch)
- {
- }
- protected void wiz_NextButtonClick(object sender, WizardNavigationEventArgs e)
- {
- try
- {
- if (SelectBatchByTerminalUC.Batch == 0)
- throw new Exception("Please select a Batch Number to continue");
- // Now we can query the data for the deposit
- DAL.CashTrack.VwDepositsByBatchCollection deposit = new DAL.CashTrack.VwDepositsByBatchCollection().Where(DAL.CashTrack.VwDepositsByBatch.Columns.Batch, SelectBatchByTerminalUC.Batch).OrderByDesc(DAL.CashTrack.VwDeposits.Columns.AccountNumber).Load();
- if (deposit.Count == 0)
- throw new Exception("Sorry... We are unable to locate any deposits for the selected batch");
- BatchNumberLabel.Text = Convert.ToString(deposit[0].Batch);
- TerminalLabel.Text = "TBD"; //deposit[0].TerminalId;
- Grid1.DataSource = DAL.CashTrack.VwDepositsByBatch.FetchByParameter(DAL.CashTrack.VwDepositsByBatch.Columns.Batch, SelectBatchByTerminalUC.Batch, SubSonic.OrderBy.Asc(DAL.CashTrack.VwDepositsByBatch.Columns.DateX));
- Grid1.DataBind();
- }
- catch (Exception ex)
- {
- e.Cancel = true;
- Savitar.Web.Utils.Popup.ShowDialog(this, ex.Message);
- }
- }
- }
The page works but it displays all the terminals, I want to change the following line to use the terminal selected in the user control, instead of the LoggedInUser
Expand|Select|Wrap|Line Numbers
- TerminalDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetTerminalForBatch(Global.LoggedInUser.FkBanksID.Value).GetDataSet();
Expand|Select|Wrap|Line Numbers
- ALTER PROCEDURE [dbo].[spGetTerminalForBatch]
- (
- @BankID INT
- )
- AS
- SELECT DISTINCT TerminalId
- FROM vwDepositsByBatch
- WHERE fkbankId = @BankID AND TerminalID <> '0'
- ORDER BY TerminalId
Any help would be appreaciated, let me know if you don't understand what I wrote, i'll try and explain it a bit more.