Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with adding extra string item to a data-bound list of int data

Posted on 2009-05-09
11
Medium Priority
?
236 Views
Last Modified: 2013-12-17
I need to have a data-bound list as below:

(Generate New Customer Id)
23
22
21
etc
The code below gave this error:
Error      1      'System.EventArgs' does not contain a definition for 'InputParameter' and no extension method 'InputParameter' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)      C:\Inetpub\wwwroot\ParkRanger\Units\NewUnit.aspx.cs      83      40      C:\...\ParkRanger\


// Handling the extra item with custom code
protected void Get_CustomerIdFromCustomers(object sender, EventArgs e)
    {
        string CustomerId = ((string)e.InputParameter["Customer_id"].value == "Generate New Customer") ;
 
        
        // string CustomerId = ddlCustomerId.SelectedItem.Text.ToString();
 
        // manually call the method
        GenerateNewCustomerID generateNewCustomerId;
        generateNewCustomerId = addUnit.GetGeneratedCustomerNewId(CustomerId);
 
       GeneratedCustomerId = generateNewCustomerId._GenerateNewCustomerId;
 
    }

Open in new window

0
Comment
Question by:Projack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24345886
Not really sure what you are trying to do here, but one thing is sure, EventArgs object doesn't contain anything useful for you here.

Do you mean to add a different piece of data based on the content of the record? Because that can best be done on the RowDataBinding event.
0
 
LVL 39

Expert Comment

by:abel
ID: 24345892
Can you update with:

- what control are you using
- how does the ASPX look like, meaning: the parts you are referencing
- where do you expect to use Get_CustomerIdFromCustomers and where you have declared it for using (i.e., it seems to be used as an event, but it doesn't look like an event).
0
 

Author Comment

by:Projack
ID: 24346161
what control are you using
<asp:DropDownList ID="ddlCustomerId" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="Get_CustomerIdFromCustomers">
</asp:DropDownList>
how does the ASPX look like, meaning: the parts you are referencing

// Needed to bind the data bound controls to the data source
ddlCustomerId.DataSource = addUnit.GetCustomerId();
ddlCustomerId.DataTextField = "Customer_Id";
ddlCustomerId.DataBind();
ddlCustomerId.Items.Insert(0, "Generate New Customer Id");  
 where do you expect to use Get_CustomerIdFromCustomers and
protected void createUnit_Click(object sender, EventArgs e)
{
// Implemented F2.6
// display paging controls
if (testCustomerId > 0)
{
txtCustomerId.Text = oldCustomerId;
}
else if (testCustomerId < 1)
{
txtCustomerId.Text = GeneratedCustomerId;
}
else
{
// invalid value
throw new Exception(" invalid value for customer id");
}
where you have declared it for using
 
public GenerateNewCustomerID GetGeneratedCustomerNewId(string customerId)
{
// get a configured DbCommand object
DbCommand command = GenericDataAccess.CustomerCreateCommand();
// set the stored procedure name
command.CommandText = "adm_GenerateNewCustomerId";
// create a new parameter
DbParameter parameter = command.CreateParameter();
parameter.ParameterName = "@CustomerId";
parameter.Value = customerId;
parameter.DbType = DbType.String;
parameter.Size = 50;
command.Parameters.Add(parameter);
// execute the stored procedure
DataTable table = GenericDataAccess.ExecuteSelectCommand(command);
GenerateNewCustomerID generateNewCustomerId = new GenerateNewCustomerID();
if (table.Rows.Count > 0)
{
// get the first table row
DataRow dr = table.Rows[0];
// get user details
generateNewCustomerId._GenerateNewCustomerId = dr["Customer_id"].ToString();
}
return generateNewCustomerId;
}
0
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24346184
Aha, so basically, revisiting your original question, you want to know whether this newly added element is selected or not, am I right? What about:



// this
bool isFirst = ddlCustomerId.SelectedValue == "Generate New Customer";
 
// or this
bool isFirst = ddlCustomerId.SelectedIndex == 0;

Open in new window

0
 

Author Comment

by:Projack
ID: 24346185
(Generate New Customer Id)
23
22
21
etc
Fo example on clicking ( Generate New Customer Id) from the dropdown below I want the this event, OnSelecte IndexChanged="Get_CustomerIdFromCustomers to retrieve the max id for me from the procedure below

<asp:DropDownList ID="ddlCustomerId" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="Get_CustomerIdFromCustomers">
</asp:DropDownList>

LTER PROCEDURE [dbo].[adm_GenerateNewCustomerId]
@CustomerId int

AS
BEGIN
if @CustomerId = 'Generate New Customer Id'
select MAX(Customer_id) + 1 from customers

END

what control are you using
<asp:DropDownList ID="ddlCustomerId" runat="server" AutoPostBack="true" 
OnSelectedIndexChanged="Get_CustomerIdFromCustomers"> 
</asp:DropDownList>
 
how does the ASPX look like, meaning: the parts you are referencing
 
// Needed to bind the data bound controls to the data source 
ddlCustomerId.DataSource = addUnit.GetCustomerId(); 
ddlCustomerId.DataTextField = "Customer_Id"; 
ddlCustomerId.DataBind(); 
ddlCustomerId.Items.Insert(0, "Generate New Customer Id");  
 
where do you expect to use Get_CustomerIdFromCustomers and 
protected void createUnit_Click(object sender, EventArgs e) 
{ 
// Implemented F2.6 
// display paging controls 
if (testCustomerId > 0) 
{ 
txtCustomerId.Text = oldCustomerId; 
} 
else if (testCustomerId < 1) 
{ 
txtCustomerId.Text = GeneratedCustomerId; 
} 
else 
{ 
// invalid value 
throw new Exception(" invalid value for customer id"); 
} 
 
where you have declared it for using 
 
public GenerateNewCustomerID GetGeneratedCustomerNewId(string customerId) 
{ 
// get a configured DbCommand object 
DbCommand command = GenericDataAccess.CustomerCreateCommand(); 
// set the stored procedure name 
command.CommandText = "adm_GenerateNewCustomerId"; 
// create a new parameter 
DbParameter parameter = command.CreateParameter(); 
parameter.ParameterName = "@CustomerId"; 
parameter.Value = customerId; 
parameter.DbType = DbType.String; 
parameter.Size = 50; 
command.Parameters.Add(parameter); 
// execute the stored procedure 
DataTable table = GenericDataAccess.ExecuteSelectCommand(command); 
GenerateNewCustomerID generateNewCustomerId = new GenerateNewCustomerID(); 
if (table.Rows.Count > 0) 
{ 
// get the first table row 
DataRow dr = table.Rows[0]; 
// get user details 
generateNewCustomerId._GenerateNewCustomerId = dr["Customer_id"].ToString(); 
} 
return generateNewCustomerId; 

Open in new window

0
 

Author Comment

by:Projack
ID: 24346405
But the code below is not firing the onselectedchange event. And the code is thtowing input error
bool isFirst = ddlCustomerId.SelectedValue == "Generate New Customer";
Why or how can I make the code below to fire event when Generate New Customer is selected from dropdownlist

0
 
LVL 39

Assisted Solution

by:abel
abel earned 2000 total points
ID: 24347342
There's no way you can fire the OnSelectionChange event when there is not change in the selection. However, the common thing to do, is to add yet another extra field in the dropdownlist, i.e.:

ddlCustomerId.Items.Insert(0, "Please make a choice");
ddlCustomerId.Items.Insert(1, "Generate New Customer Id");
which will show the customer the "Please make a choice" item and will create a OnSelectionChange event.

As you can see now, the code I posted contained a copy and paste error, equal to the copy and paste error in your original code. The word "Id" is missing, which is why the boolean is always false:

bool isFirst = ddlCustomerId.SelectedValue == "Generate New Customer Id";
or:

bool isFirst = ddlCustomerId.SelectedIndex == 1;
further down in your code you can use this boolean to create your new items in your database.

-- Abel --

0
 

Author Comment

by:Projack
ID: 24348451
// dropdownlist
(Generate New Customer Id)
23
22
21
etc
// paste error in your original code. is changed and the code below is still not firing the event:
bool isFirst = ddlCustomerId.SelectedValue == "Generate New Customer Id";
Other items are firing the OnSelectionChange event  except the Generate New Customer Id extra item. How can I make this fire event?
can this help
   string CustomerId = ((string)e.InputParameter["Customer_id"].value == "Generate New Customer            
0
 
LVL 39

Assisted Solution

by:abel
abel earned 2000 total points
ID: 24348460
Have you tried putting a breakpoint at the beginning of the event? If you change an item, it will be hit. My last comment explains you that you need to add at least two items to have the change event hit, or you need to default to another item then the one with "Generate New Customer Id".

The last line of code above (your comment) is creating a boolean. I don't know why you do that, I didn't really comment on it. e.InputParameter does not exist, so as long as that part is in your project, you cannot compile. In short: remove that line.

If you say that the others do raise the event, I assume you do so without the above line? Because with it, nothing can happen... (unless you run the last-known-good code, the debugger usually asks for that).
0
 
LVL 39

Assisted Solution

by:abel
abel earned 2000 total points
ID: 24348465
PS: there's no difference in ASP.NET in handling dropdownlist change events for items that are added or for items that are databound.

I assume you have the databound and the addition of the extra item behind an "if (this.IsPostBack)" block to prevent it from binding each time again.
0
 

Author Closing Comment

by:Projack
ID: 31579829
You are a good teacher
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question