?
Solved

How do I get the value out of a dataList control field and put it in a variable?  (ASP/C#)

Posted on 2009-04-14
9
Medium Priority
?
382 Views
Last Modified: 2013-12-17
How do I get the value out of a dataList control field and put it in a variable?
The field name is imgID (int)
I would like to put this value in a variable called phID.  How do i do this?
0
Comment
Question by:bmanmike39
[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
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:havj123
ID: 24144951
Find the control using FindControl method and put it in a variable

Like
TextBox tb = (TextBox)datalist1.FindControl("text1");
int x;
x = convert.ToInt32(tb.Text);
0
 

Author Comment

by:bmanmike39
ID: 24145099
I get the following  ERROR:
"object reference not set to an instance"
0
 
LVL 6

Expert Comment

by:havj123
ID: 24145121
in which event of datalist u find ur control. Can u show me the code
0
Industry Leaders: 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!

 

Author Comment

by:bmanmike39
ID: 24145137
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{


string b;
Label z = (Label)(DataList1.FindControl("Lbl1"));
Response.Redirect(z.ToString());
}

0
 
LVL 3

Expert Comment

by:OmerFarukZ
ID: 24145164
try this code

TextBox tb = (TextBox)datalist1.Items[0].FindControl("text1");
int x;
x = convert.ToInt32(tb.Text);
0
 
LVL 6

Expert Comment

by:havj123
ID: 24145266
You can find textbox inside datalist in a imagebutton click event. IF ur image button is inside the datalist then use your code in datalist itemcommand event.

0
 
LVL 6

Expert Comment

by:havj123
ID: 24145319
Is ur image button is inside datalist?
0
 

Author Comment

by:bmanmike39
ID: 24145599
yes it is
0
 
LVL 6

Accepted Solution

by:
havj123 earned 2000 total points
ID: 24145707
ok then in datalist itemcommand event find ur control like this

Label lbl = e.Item.FindControl("Lbl1") as Label;
int i;
if(lbl != null)
{
  i = convert.ToInt32(lbl.Text);
}
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

719 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