473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#-WEB: Selected Value in User Control

Eleven
19
Hi everybody!

I've got a User Control "SelectBatchByTerminal", that has two dropdown lists, "TerminalDropDownList" and "BatchDropDownList".

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class UserControls_SelectBatchByTerminal : System.Web.UI.UserControl
  13. {
  14.     public delegate void BatchChangedDelegate(Int32 Batch);
  15.     public event BatchChangedDelegate OnBatchChanged;
  16.  
  17.     public Int32 Batch
  18.     {
  19.         get
  20.         {
  21.             if (BatchDropDownList.Items.Count == 0)
  22.                 return 0;
  23.  
  24.             if (BatchDropDownList.SelectedValue == null)
  25.                 return 0;
  26.  
  27.             if (BatchDropDownList.SelectedIndex == 0)
  28.                 return 0;
  29.  
  30.             return Convert.ToInt32(BatchDropDownList.SelectedValue);
  31.         }
  32.     }
  33.  
  34.     public string SelectedTerminalID
  35.     {
  36.         get
  37.         {
  38.             if ((TerminalDropDownList.Items.Count == 0) || (TerminalDropDownList.SelectedIndex == 0))
  39.                 return "";
  40.  
  41.             return TerminalDropDownList.SelectedValue;
  42.         }
  43.     }
  44.  
  45.     public string SelectedBatch
  46.     {
  47.         get
  48.         {
  49.             if ((BatchDropDownList.Items.Count == 0) || (BatchDropDownList.SelectedIndex == 0))
  50.                 return "";
  51.  
  52.             return BatchDropDownList.SelectedValue;
  53.         }
  54.     }
  55.  
  56.     protected void Page_Load(object sender, EventArgs e)
  57.     {
  58.         if (!IsPostBack)
  59.             BindTerminals();
  60.     }
  61.  
  62.     protected void BindTerminals()
  63.     {
  64.         Trace.Write("Binding Data");
  65.         TerminalDropDownList.DataTextField = DAL.CashTrack.Terminals.Columns.TerminalId;
  66.         TerminalDropDownList.DataValueField = DAL.CashTrack.Terminals.Columns.TerminalId;
  67.         //Line below to be re-written to use SelectedTerminalId instead of LoggedInUser
  68.         TerminalDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetTerminalForBatch(Global.LoggedInUser.FkBanksID.Value).GetDataSet();
  69.         TerminalDropDownList.DataBind();
  70.         TerminalDropDownList.Items.Insert(0, new ListItem(">> Select <<", "0"));
  71.         TerminalDropDownList.SelectedIndex = 0;
  72.     }
  73.  
  74.     protected void BindBatches(string terminal)
  75.     {
  76.         BatchDropDownList.DataTextField = DAL.CashTrack.Deposits.Columns.Batch;
  77.         BatchDropDownList.DataValueField = DAL.CashTrack.Deposits.Columns.Batch;
  78.         BatchDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetBatchByTerminal(terminal).GetDataSet();
  79.         BatchDropDownList.DataBind();
  80.         BatchDropDownList.Items.Insert(0, new ListItem(">> Select <<", "0"));
  81.         BatchDropDownList.SelectedIndex = 0;
  82.     }
  83.  
  84.     protected void TerminalDropDownList_SelectedIndexChanged(object sender, EventArgs e)
  85.     {
  86.         BindBatches(TerminalDropDownList.SelectedValue);
  87.     }
  88.  
  89.     protected void BatchDropDownList_SelectedIndexChanged(object sender, EventArgs e)
  90.     {
  91.         if (this.Batch != 0)
  92.         {
  93.             if (OnBatchChanged != null)
  94.                 OnBatchChanged(this.Batch);
  95.         }
  96.     }
  97. }
  98.  
And I've got a page "DepositPerBatch" that uses that UC..
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class Deposits_DepositPerBatch : System.Web.UI.Page
  13. {
  14.     protected override void OnInit(EventArgs e)
  15.     {
  16.         base.OnInit(e);
  17.  
  18.         wiz.ActiveStepIndex = 0;
  19.         SelectBatchByTerminalUC.OnBatchChanged += new UserControls_SelectBatchByTerminal.BatchChangedDelegate(OnBatchChanged);
  20.     }
  21.  
  22.     protected void Page_Load(object sender, EventArgs e)
  23.     {
  24.  
  25.     }
  26.  
  27.     protected void OnBatchChanged(Int32 Batch)
  28.     {
  29.  
  30.     }
  31.  
  32.     protected void wiz_NextButtonClick(object sender, WizardNavigationEventArgs e)
  33.     {
  34.         try
  35.         {
  36.             if (SelectBatchByTerminalUC.Batch == 0)
  37.                 throw new Exception("Please select a Batch Number to continue");
  38.  
  39.             // Now we can query the data for the deposit
  40.             DAL.CashTrack.VwDepositsByBatchCollection deposit = new DAL.CashTrack.VwDepositsByBatchCollection().Where(DAL.CashTrack.VwDepositsByBatch.Columns.Batch, SelectBatchByTerminalUC.Batch).OrderByDesc(DAL.CashTrack.VwDeposits.Columns.AccountNumber).Load();
  41.             if (deposit.Count == 0)
  42.                 throw new Exception("Sorry... We are unable to locate any deposits for the selected batch");
  43.  
  44.             BatchNumberLabel.Text = Convert.ToString(deposit[0].Batch);
  45.             TerminalLabel.Text = "TBD"; //deposit[0].TerminalId;
  46.  
  47.             Grid1.DataSource = DAL.CashTrack.VwDepositsByBatch.FetchByParameter(DAL.CashTrack.VwDepositsByBatch.Columns.Batch, SelectBatchByTerminalUC.Batch, SubSonic.OrderBy.Asc(DAL.CashTrack.VwDepositsByBatch.Columns.DateX));
  48.             Grid1.DataBind();
  49.         }
  50.         catch (Exception ex)
  51.         {
  52.             e.Cancel = true;
  53.             Savitar.Web.Utils.Popup.ShowDialog(this, ex.Message);
  54.         }
  55.     }
  56. }
  57.  

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
  1. TerminalDropDownList.DataSource = DAL.CashTrack.Sprocs.SpGetTerminalForBatch(Global.LoggedInUser.FkBanksID.Value).GetDataSet();
  2.  
I know I have to change my Stored Procedure as well, which currently looks like this:
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[spGetTerminalForBatch]
  2. (
  3.   @BankID INT
  4. )
  5. AS
  6.  
  7. SELECT DISTINCT TerminalId
  8. FROM vwDepositsByBatch
  9. WHERE fkbankId = @BankID AND TerminalID <> '0'
  10. ORDER BY TerminalId
  11.  
The TerminalId is a string!

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.
Mar 11 '08 #1
1 1518
Eleven
19
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[spGetTerminalForBatch]
  2. (
  3.   @Terminal VARCHAR(8)
  4. )
  5. AS
  6.  
  7.  
  8. SELECT DISTINCT TerminalId
  9. FROM vwDepositsByBatch
  10. WHERE TerminalId = @Terminal
  11. ORDER BY TerminalId
  12.  
I wrote a new SP but I'm not really sure what to edit on my C# code
Mar 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nemo | last post by:
I have problem to get my dates from my user control. The problems is that the datetimes sets after when I get the values from my aspx page. Here is how my user control lock likes. private...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
6
by: Mary Kerrigan | last post by:
I have a user control (menu) with a data list: <asp:DataList id="MyList" runat="server"> <ItemTemplate> <asp:hyperlink cssclass="MenuUnselected" id="myLink1" Text='<%#...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
0
by: ab_j | last post by:
I have a user control that contains a dropdown which I want to use as a menu on multiple .aspx pages. Basically, all I am trying to do is pass the selected value of the dropdown in the user...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
9
by: TCORDON | last post by:
I have a user control that contains 2 image buttons, when you click one of them, both must change the image source, the thing is that the first time you click any one of them the page appears to do...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
3
by: Joe | last post by:
Hello All, I am developing a webform which creates ArrayLists of people's names and addresses (the values are retrieved from an xml file) and dynamically drops a user control onto the webform...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.