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
376 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
Comment Utility
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
Comment Utility
I get the following  ERROR:
"object reference not set to an instance"
0
 
LVL 6

Expert Comment

by:havj123
Comment Utility
in which event of datalist u find ur control. Can u show me the code
0
 

Author Comment

by:bmanmike39
Comment Utility
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{


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

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Expert Comment

by:OmerFarukZ
Comment Utility
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
Comment Utility
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
Comment Utility
Is ur image button is inside datalist?
0
 

Author Comment

by:bmanmike39
Comment Utility
yes it is
0
 
LVL 6

Accepted Solution

by:
havj123 earned 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

17 Experts available now in Live!

Get 1:1 Help Now