Go Premium for a chance to win a PS4. Enter to Win

x
?
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
?
383 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

963 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