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
377 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
  • 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
 

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now