473,811 Members | 3,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-WEB: Selected Value in User Control

Eleven
19 New Member
Hi everybody!

I've got a User Control "SelectBatchByT erminal", that has two dropdown lists, "TerminalDropDo wnList" and "BatchDropDownL ist".

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 "DepositPerBatc h" 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 1537
Eleven
19 New Member
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
1256
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 void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack)
0
1926
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.. Chris. code :
6
1922
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='<%# Container.DataItem("Subject") %>' NavigateUrl='<%# "../productlist.aspx?SubjectID=" & Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
4
2465
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, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
0
2447
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 control to the main ..aspx page. In an attempt to make it more clear on what I am talking about, here is the order of events in page life cycle (from http://www.dotnetspider.com/technology/KBPages/789.aspx) ..ascx - OnInit() ..ascx - Page_Init()
5
5995
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 event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset): Public Class DatePicker2...
9
2893
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 a postbak, but the image source or the image displayed does not change until I click one of the images a second time, why dows it take 2 clicks for the user to "refresh"? TIA!
9
2339
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 into the place holder. This is done dynamically based on the choice they selected. This user control has a datagrid in it that supports paging. When I click on the next or prev buttons of the datagrid in a user control it should display the next page...
3
1520
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 and populates it with the required names. Once the user selects a name, the webform will then drop another user control (the same control) onto itself and populate it with the selected name's addresses. The user control is a combination of an...
6
2645
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 in the page and I've got code to get the selected value from it in the Radiobuttonlist_SelectedIndexChanged event. The code in there is: Protected Sub rblFMSValue_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
0
9731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.