Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I am using the ItemDataBound event to format some of the colours in my datagrid depending on the contents of the row, it works great. Problem is if i do a refresh i lose all the changes made by ItemDataBound which I don't want happening. Unless something new has been added to the grid I really don't want to have to re-bind my grid everytime a refresh occurs. For the most part I don't tend to add things to my grid. Is there some way of ensuring that my ItemDataBound changes can remain, maybe in viewstate or something?
  • 2 weeks later...
Posted

Heres my page_load

private void Page_Load(object sender, System.EventArgs e)
	{

		String prefix = PathPrefix;
				
		NoteHeader_PNL.BackImageUrl = prefix + "/images/completeNoteHeader.gif";

		Background.Attributes.Add("BackGround", prefix + "/images/background.gif");
		//RowHeaderBar.Attributes.Add("RowHeaderBar", prefix + "/images/barForNotes.gif");
					
		String defaultMode = JobAdder.DefaultNoteAdd;

		if (defaultMode == "normalNoteAdd")
		{
			JobAdderForTheNoteScreen_PNL.Style.Add( "display", "none" );
		}
		
		if (defaultMode == "editForDefault")
		{
			JobAdderForTheNoteScreen_PNL.Style.Add( "display", "none" );
			//JobAdderForTheNoteScreen_PNL.Visible = false;
			NoteHeader_PNL.Visible = true;
			JobAdder.DefaultNoteAdd = null;
		}

		if (JobAdder.Calendar_Checked_Status == true)
		{
			NoteList_LST.Visible = false;
			Calendar_On_Notescreen_PNL.Visible = true;
		}
		
		if (JobAdder.Calendar_Checked_Status == false)
		{
			NoteList_LST.Visible = true;
			Calendar_On_Notescreen_PNL.Visible = false;
		}


		if (IsPostBack)
		{
		}

		else		
		{				
			//Its a regular select existing job
			roleid = links.RoleID;
	
			if (roleid == 1)
			{
				viewMode = JobViewerForAdmin.JobViewMode;
								
				if (viewMode == "view")
				{
					DisplayNotes();
					JobViewerForAdmin.JobViewMode = "";
				}
					
			}
			else
			{
				viewMode = JobWithNoteViewer.JobViewMode;
								
				if (viewMode == "view")
				{
					DisplayNotes();
					JobWithNoteViewer.JobViewMode = "";
				}

			}
		}				

		// First time around, lets populate the list boxes.
		if (!IsPostBack)
		{
			PopulateActionsDropDown();  
		}

			// Otherwise its a basic job add
		else
		{
					
		}


	}







Heres my bind function

private void BindNotes()
	{
		roleid = links.RoleID;
		
		if (roleid == 1)
		{
			userID = links.UserID;//JobViewerForAdmin.UsrID;

			jobID = (int)Session["JobID_By_Session"];
			//jobID = JobViewerForAdmin.JobID;
			if (jobID == 0)    // I put these in here for the add new job section
			{					// that needs to return an update view
				//jobID = (int)ViewState["jobID"];
				jobID = (int)Session["JobID_By_Session"];//JobSystem.JobIDforDefault;
				//JobViewerForAdmin.JobID = 0;//xyz

			}
		}
		else
		{
			userID = links.UserID;
			jobID = (int)Session["JobID_By_Session"];//JobWithNoteViewer.JobID;
			if (jobID == 0)
			{
				jobID = (int)Session["JobID_By_Session"];//JobSystem.JobIDforDefault;
				//JobWithNoteViewer.JobID = 0;//xyz
			}
		}
	
		noteSystem = new NoteSystem();
		noteData = noteSystem.GetNotesByUserAndJobID(userID,jobID);

	// Lets get the note id's and save them in our array for later
		DataTable noteTable = noteData.Tables[NotesData.NOTES_TABLE];

		if (NotesData.FlagUpdateNote != true)
		{
			noteIDList.Clear();
	

			foreach (DataRow noteID in noteTable.Rows)
			{
				int noteid = Int32.Parse(noteID[NotesData.NOTES_ID_FIELD].ToString());
		
				noteIDList.Add(noteid);
				IEnumerator E = arraylist.GetEnumerator();
				E.MoveNext();
			}
		}

		noteView = noteData.Tables[NotesData.NOTES_TABLE].DefaultView;

		NoteList_LST.DataSource = noteView;
		NoteList_LST.DataBind();
	}





heres my ItemDataBound event

private void NoteList_LST_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
	{

		String readStatus;
		String bywho;
		//int userID = links.UserID;
		String tmpUserID = userID.ToString();


		ListItemType lit = e.Item.ItemType; 

		if (lit == ListItemType.Item || lit == ListItemType.AlternatingItem)
		{
			readStatus = Convert.ToString(DataBinder.Eval(e.Item.DataItem, NotesData.NOTE_READ_FIELD));
			Button button = e.Item.FindControl("Read_Note_BTN") as Button;

			String Action;
			Action = Convert.ToString(DataBinder.Eval(e.Item.DataItem, NotesData.FK_ACTION_PERFORMED_FIELD));

			Button edit = e.Item.FindControl("Edit_Note_BTN") as Button;
			Label label = e.Item.FindControl("Total_Label") as Label;
			HtmlTableCell header = e.Item.FindControl("RowHeaderBar") as HtmlTableCell;
			HtmlTableCell header_for_system = e.Item.FindControl("RowHeaderBar_For_System") as HtmlTableCell;
			HtmlTableCell header_for_unread = e.Item.FindControl("RowHeaderBar_For_UnRead") as HtmlTableCell;

			header.Visible = false;
			header_for_system.Visible = false;
			header_for_unread.Visible = false;
			
			bywho = Convert.ToString(DataBinder.Eval(e.Item.DataItem, NotesData.FK_USERID_FIELD));
						
			if(bywho == tmpUserID) // The user that logged on created the note
			{
				if(Action != "null")									// Read notes with read button removed
				{														
					header.Visible = true;								// blue bar VISIBLE
					header_for_system.Visible = false;					// grey bar	INVISIBLE
					button.Visible = false;								// They don't need to have read button
					edit.Visible = true;								// This person can edit their own note
					header_for_unread.Visible = false;					// because they created it.

					if (Action == "Comment")
					{
						label.Visible = false;
					}
				}	

				if(Action == "null")									// System notes with read button removed
				{
					e.Item.BackColor = System.Drawing.Color.LightGray;
					button.Visible = false;
					edit.Visible = false;
					label.Visible = false;
					header.Visible = false;
					header_for_system.Visible = true;
					header_for_unread.Visible = false;
				}
				
			}
			
			else			// This user is receiving notes that someone else created
			{
				if(Action != "null" && readStatus != "Read")			// Notes that are unread
				{
					e.Item.BackColor = System.Drawing.Color.IndianRed;
					header.Visible = false;								// blue bar VISIBLE
					header_for_system.Visible = false;					// grey bar INVISIBLE
					button.Visible = true;
					edit.Visible = false;								// This person can't edit this note
					header_for_unread.Visible = true;					// because they didn't create it
					
					if (Action == "Comment")							// This removes totals for comments
					{													// A comment is the only category
						label.Visible = false;							// without a total
					}
				}

				if(Action != "null" && readStatus == "Read" )			// Read notes with read button removed
				{														
					header.Visible = true;								// blue bar VISIBLE
					header_for_system.Visible = false;					// grey bar	INVISIBLE
					button.Visible = false;
					edit.Visible = false;								// This person can't edit this note
					header_for_unread.Visible = false;					// because they didn't create it
					
					if (Action == "Comment")							// This removes totals for comments
					{													// A comment is the only category
						label.Visible = false;							// without a total
					}

				}	

				if(Action == "null" && readStatus != "Read")			// System Notes that are unread
				{
					e.Item.BackColor = System.Drawing.Color.IndianRed;
					button.Visible = true;
					edit.Visible = false;								// Can't edit system notes
					label.Visible = false;
					header.Visible = false;
					header_for_system.Visible = true;
					header_for_unread.Visible = false;

					//RowHeaderBar_For_System.Visible = false;
				}

				if(Action == "null" && readStatus == "Read")			// System notes with read button removed
				{
					e.Item.BackColor = System.Drawing.Color.LightGray;
					button.Visible = false;
					edit.Visible = false;								// Can't edit system notes
					label.Visible = false;
					header.Visible = false;
					header_for_system.Visible = true;
					header_for_unread.Visible = false;
				}
				

			}

		}
	}

 

heres my html

 

 

 

 

 

I could post the whole thing but its nearly a thousand lines long. Hope this doesn't put you off!!

 

Thanks for your help

 

[edit]Please use

 tags [/cs ]: Robby[/color] [/edit]
Posted

sorry i missed this, this is invoke from the page_load:

 

 

public void DisplayNotes()

{

if (JobAdder.DefaultNoteAdd == "normalNoteAdd")

{

JobAdderForTheNoteScreen_PNL.Style.Add( "display", "none" );

NoteHeader_PNL.Visible = true;

JobAdder.DefaultNoteAdd = null;

}

 

else

{

JobAdderForTheNoteScreen_PNL.Style.Add( "display", "block" );

NoteHeader_PNL.Visible = false;

//JobViewerForAdmin.JobID = 0;

}

 

 

BindNotes();

 

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...