Click here to Skip to main content
15,911,646 members
Home / Discussions / C#
   

C#

 
QuestionCopying UserControl Variables to another instance of the UserControl [modified] Pin
TheBlindWatchmaker6-Jul-06 7:39
TheBlindWatchmaker6-Jul-06 7:39 
AnswerRe: Copying UserControl Variables to another instance of the UserControl Pin
Dustin Metzgar6-Jul-06 7:55
Dustin Metzgar6-Jul-06 7:55 
GeneralRe: Copying UserControl Variables to another instance of the UserControl Pin
TheBlindWatchmaker6-Jul-06 8:13
TheBlindWatchmaker6-Jul-06 8:13 
GeneralRe: Copying UserControl Variables to another instance of the UserControl Pin
Dustin Metzgar6-Jul-06 8:28
Dustin Metzgar6-Jul-06 8:28 
QuestionTransferring data from database to database Pin
Stephen Hurt6-Jul-06 6:27
Stephen Hurt6-Jul-06 6:27 
AnswerRe: Transferring data from database to database Pin
led mike6-Jul-06 6:40
led mike6-Jul-06 6:40 
AnswerRe: Transferring data from database to database Pin
BambooMoon6-Jul-06 7:09
BambooMoon6-Jul-06 7:09 
Questionif/else statement for command button; object reference not set to an instance error Pin
leckey6-Jul-06 6:15
leckey6-Jul-06 6:15 
I have a command button that I basically want it to do one thing the first time, and something else on subsequent clicks.

I have a datagrid and the user clicks a button to add a line. The first time this happens, I need to go thru the BindData method to get everything initialized.

For subsequent clicks, I just want it to add the lines. I don't want to have to go through a postback, because I either end up with the first added line reset or I get the object reference not set to an instance error.

private void Button2_Click(object sender, System.EventArgs e)<br />
		{	<br />
<br />
			DataGridItemCollection items = dgParts.Items;<br />
			int rows = items.Count;<br />
			if (rows == 0)<br />
			{<br />
				BindData();<br />
				DataTable dt = ds.Tables["Rest"];<br />
				DataRow row;<br />
				row = dt.NewRow();	<br />
				strPartNumberInputReference = txtSearchPart.Text;<br />
				row["PartNumber"] = strPartNumberInputReference; <br />
				row["DrawingNumber"]=DBNull.Value;<br />
				row["DrawingRevision"]=DBNull.Value;<br />
				row["DwgPath"]=DBNull.Value;<br />
				dt.Rows.Add(row);			<br />
				dt.AcceptChanges();			  <br />
				dgParts.DataSource=dt;			<br />
				dgParts.DataBind();<br />
			}<br />
<br />
			else<br />
			{<br />
				DataRow row;<br />
				row = dt.NewRow();	<br />
				strPartNumberInputReference = txtSearchPart.Text;<br />
				row["PartNumber"] = strPartNumberInputReference; <br />
				row["DrawingNumber"]=DBNull.Value;<br />
				row["DrawingRevision"]=DBNull.Value;<br />
				row["DwgPath"]=DBNull.Value;<br />
				dt.Rows.Add(row);			<br />
				dt.AcceptChanges();			  <br />
				dgParts.DataSource=dt;			<br />
				dgParts.DataBind();<br />
			}<br />
		<br />
<br />
<br />
<br />
		<br />
<br />
		}


When I click the button the second time my row count does say it has one row and tries to run through the else statement, but I get the null error thing.

I've been stuck on this for several days so if someone has any idea of a solution you will be my hero!
AnswerRe: if/else statement for command button; object reference not set to an instance error Pin
Guffa6-Jul-06 6:21
Guffa6-Jul-06 6:21 
GeneralRe: if/else statement for command button; object reference not set to an instance error Pin
leckey6-Jul-06 7:08
leckey6-Jul-06 7:08 
GeneralRe: if/else statement for command button; object reference not set to an instance error Pin
Paul Conrad6-Jul-06 7:17
professionalPaul Conrad6-Jul-06 7:17 
GeneralRe: if/else statement for command button; object reference not set to an instance error [modified] Pin
leckey6-Jul-06 7:55
leckey6-Jul-06 7:55 
GeneralRe: if/else statement for command button; object reference not set to an instance error Pin
Paul Conrad6-Jul-06 8:00
professionalPaul Conrad6-Jul-06 8:00 
GeneralRe: if/else statement for command button; object reference not set to an instance error Pin
Paul Conrad6-Jul-06 8:04
professionalPaul Conrad6-Jul-06 8:04 
AnswerRe: if/else statement for command button; object reference not set to an instance error Pin
Guffa6-Jul-06 8:16
Guffa6-Jul-06 8:16 
GeneralRe: if/else statement for command button; object reference not set to an instance error Pin
leckey6-Jul-06 8:40
leckey6-Jul-06 8:40 
AnswerRe: if/else statement for command button; object reference not set to an instance error Pin
Paul Conrad6-Jul-06 6:59
professionalPaul Conrad6-Jul-06 6:59 
QuestionListView Item/Subitem backcolor solution Pin
Aaron Dilliard6-Jul-06 5:33
Aaron Dilliard6-Jul-06 5:33 
QuestionPlugin can't see referenced code Pin
berry seltzer6-Jul-06 5:17
berry seltzer6-Jul-06 5:17 
QuestionHow to retrieve image with Html Pin
Bluebamboo6-Jul-06 5:13
Bluebamboo6-Jul-06 5:13 
AnswerRe: How to retrieve image with Html Pin
Not Active6-Jul-06 5:32
mentorNot Active6-Jul-06 5:32 
GeneralRe: How to retrieve image with Html Pin
Bluebamboo6-Jul-06 5:46
Bluebamboo6-Jul-06 5:46 
AnswerRe: How to retrieve image with Html Pin
led mike6-Jul-06 5:42
led mike6-Jul-06 5:42 
GeneralRe: How to retrieve image with Html Pin
Bluebamboo6-Jul-06 5:58
Bluebamboo6-Jul-06 5:58 
GeneralRe: How to retrieve image with Html Pin
led mike6-Jul-06 6:26
led mike6-Jul-06 6:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.