Using VS 2010, C#, .NET 3.5
I have three User Defined Web Controls:
Control 1 has a ListBox and A Button
Control 2 has three Text-Boxes two DropDownLists and three Buttons
Control 3 has only a Table which is populated in code.
I have two pages:
Page 1 has Control 2 and Control 3
Page 2 has Control 1, Control 2, and Control 3
Functionality of Control 2 works perfectly on Page 1.
However, on Page 2 when the submit button is clicked, both DropDownLists ALWAYS show SelectedIndex = 0 and SelectedValue = "0".
All three Text Boxes and Buttons retain their value on both pages when the Submit Button on Control 2 is clicked. Only the DropDownLists fail to retain their value.
For reference, here is the code in the Submit Button OnClick event:
protected void btnSubmit_Click(object sender, EventArgs e)
{
clsLog.WriteLog("TrainingForm.ascx - Submit.");
tcCategoryError.Text = " ";
tcDateError.Text = " ";
tcDescriptionError.Text = " ";
tcHoursError.Text = " ";
tcMethodError.Text = " ";
foreach (Control c in this.Controls)
{
LogControls(c);
}
c_iTID = Convert.ToInt32(hTID.Value);
c_szUserName = hUserName.Value;
bool bValid = true;
DateTime dtTrainingDate = DateTime.MinValue;
string szTrainingDescription = "";
decimal dHours = 0M;
int iCategoryID = 0;
int iMethodID = 0;
if (!DateTime.TryParse(txtTrainingDate.Text, out dtTrainingDate))
{
bValid = false;
tcDateError.Text = "Please Enter Valid Training Date";
}
if (!decimal.TryParse(txtTrainingHours.Text, out dHours))
{
bValid = false;
tcHoursError.Text = "Please Enter Valid Training Hours";
}
if (this.ddlCategory.SelectedValue == "0")
{
bValid = false;
tcCategoryError.Text = "Please Select Training Category";
}
else
iCategoryID = Convert.ToInt32(this.ddlCategory.SelectedValue);
if (this.ddlTrainingMethod.SelectedValue == "0")
{
bValid = false;
tcMethodError.Text = "Please Select Training Method";
}
else
iMethodID = Convert.ToInt32(this.ddlTrainingMethod.SelectedValue);
if (txtTrainingDescription.Text.Trim() == "")
{
bValid = false;
tcDescriptionError.Text = "Please Enter Training description.";
}
else
szTrainingDescription = txtTrainingDescription.Text.Trim();
if (bValid)
{
clsData.UpdateTraining(c_iTID, "", c_szUserName, dtTrainingDate, szTrainingDescription, iCategoryID, dHours, iMethodID);
TrainingID = 0;
ClearForm();
}
OnEvent(new MyEventArgs(c_szUserName));
}
Code to populate DropDowns (part of the User Defined Control)
protected void BindddlCategory(int iCategoryID)
{
DataTable dt = clsData.GetTrainingCategories();
ddlCategory.Items.Clear();
ddlCategory.AppendDataBoundItems = true;
ddlCategory.Items.Add(new ListItem("Select Training Category", "0"));
ddlCategory.DataSource = dt;
ddlCategory.DataTextField = "TrainingCategory";
ddlCategory.DataValueField = "CID";
ddlCategory.DataBind();
if (iCategoryID != 0)
ddlCategory.SelectedValue = iCategoryID.ToString();
}
protected void BindddlCategory()
{
BindddlCategory(0);
}
protected void BindddlTrainingMethod(int iMethodID)
{
DataTable dt = clsData.GetTrainingMethods();
ddlTrainingMethod.Items.Clear();
ddlTrainingMethod.AppendDataBoundItems = true;
ddlTrainingMethod.Items.Add(new ListItem("Select Training Method", "0"));
ddlTrainingMethod.DataSource = dt;
ddlTrainingMethod.DataTextField = "TrainingCategory";
ddlTrainingMethod.DataValueField = "CID";
ddlTrainingMethod.DataBind();
if (iMethodID != 0)
ddlTrainingMethod.SelectedValue = iMethodID.ToString();
}
protected void BindddlTrainingMethod()
{
BindddlTrainingMethod(0);
}
FYI, the DDLs are NOT populated at Page load but implicitly populated when the event to show the form of the control is fired:
public void ShowTrainingEntry(int iTrainingID)
{
clsLog.WriteLog("TrainingForm.ascx - ShowTrainingEntry(" + iTrainingID.ToString() + ")");
hTID.Value = iTrainingID.ToString();
hUserName.Value = UserName;
int iCategoryID = 0;
int iMethodID = 0;
if (iTrainingID != 0)
{
DataTable dt = clsData.GetTrainingRecord(iTrainingID);
if (dt.Rows.Count == 1)
{
txtTrainingDate.Text = Convert.ToDateTime(dt.Rows[0]["TrainingDate"]).ToString("MM/dd/yyyy");
txtTrainingHours.Text = Convert.ToDecimal(dt.Rows[0]["Hours"]).ToString("N1");
txtTrainingDescription.Text = dt.Rows[0]["TrainingDescription"].ToString();
int.TryParse(dt.Rows[0]["CategoryCID"].ToString(), out iCategoryID);
int.TryParse(dt.Rows[0]["MethodCID"].ToString(), out iMethodID);
}
ShowChangeMessage(iCategoryID == 0 | iMethodID == 0);
ShowDeleteButton(true);
ShowCancelButton(true);
}
BindddlCategory(iCategoryID);
BindddlTrainingMethod(iMethodID);
tblMain.Visible = true;
}
Anyone have any ideas on why this is happening?
Thanks,
John
If you are adding the UserControls dynamically, you need to make sure they are added no later than Page_Init. This is so the controls are present when the page attempts to set the values from the PostBack.
Related
I have a DataGridView (DGV) that is NOT using data binding The data is in a SQLite DB
I have written a method that styles the DataGridView
I can populate the DGV with the id of the records in the DB and two string variables
For testing I have 4 TextBox's on the form when I click on the cells I would like to
retrieve the id to transfer that value to another form to use in SQL search
I have tried a number of methods to get data by clicking on the DGV all three are in the
posted code NO I DO NOT WANT to use data binding
SIDE NOTE I have this code working in a VB.Net application no issues
I am new to C# so the code conversion may be the real issue
SO the question is Using C# How to click on a DGV and retrieve the selected value?
public partial class frmSelect : Form
{
string gv_parentInt = "";
string gv_firstName = "";
string gv_lastName = "";
public frmSelect()
{
InitializeComponent();
}
private void frmSelect_Load(object sender, EventArgs e)
{
StyleDGV();
readFriendsData();
}
// Thried these two methods below NO RESULTS
/* private void dgvPerson_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dgvPerson.Rows[e.RowIndex];
tbID.Text = row.Cells[0].Value.ToString();
tbFName.Text = row.Cells[1].Value.ToString();
tbLName.Text = row.Cells[2].Value.ToString();
}
}*/
/*public void dgvPerson_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dgvPerson.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
tbMessage.Text = dgvPerson.SelectedCells[0].Value.ToString();
}
}*/
public void dgvPerson_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex == -1)
{
tbMessage.Text = "Col " + e.ColumnIndex + " ROW " + e.RowIndex;// for testing
tbMessage.Text = "No Clicking Here";
//return;
}
string strFName;
string strLName;
DataGridViewRow row = dgvPerson.Rows[e.RowIndex];
strFName = dgvPerson.CurrentRow.Cells[0].Value.ToString();
if (strFName != " ")
{
if (strFName == " ")
return;
int intId = System.Convert.ToInt32(row.Cells[0].Value);
gv_parentInt = intId.ToString();
tbID.Text = gv_parentInt;
strFName = row.Cells[1].Value.ToString();
gv_firstName = strFName.Trim();
tbFName.Text = gv_firstName;
strLName = row.Cells[2].Value.ToString();
gv_lastName = strLName.Trim();
tbLName.Text = gv_lastName;
}
tbMessage.Text = "No Data Here";
}
private void readFriendsData()
{
using (SQLiteConnection conn = new SQLiteConnection($"Data Source = '{"Contacts.db"}';Version=3;"))
{
conn.Open();
// The $ sign and '{String or Integer}' how to add variable to SQL Select Statement'gv_parentInt
// Must incorparate BOTH for SELECT to work
// =================================================================================
using (SQLiteCommand cmd = new SQLiteCommand($"SELECT * FROM FriendsData", conn))
{
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
gv_parentInt = rdr["FID"].ToString().Trim();
gv_firstName = rdr["fxFirstName"].ToString().Trim();
gv_lastName = rdr["fxLastName"].ToString().Trim();
dgvPerson.Rows.Add(gv_parentInt, gv_firstName, gv_lastName);
}
rdr.Close();
}
}
conn.Close();
}
//frmPrintLabel.LoadLabel();
}
public void StyleDGV()
{
this.Controls.Add(dgvPerson);
// Set Design of the DataGridView
dgvPerson.DefaultCellStyle.Font = new Font("Bold Tahoma", 11);
dgvPerson.ColumnCount = 3;
dgvPerson.Columns[0].Width = 60;
dgvPerson.Columns[1].Width = 138;
dgvPerson.Columns[2].Width = 138;
// To Set Col Header Size Mode = Enabled
// To Set Col Header Default Cell Styles DO in Properties
dgvPerson.DefaultCellStyle.BackColor = Color.LightBlue;
dgvPerson.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray;
dgvPerson.ColumnHeadersHeight = 34;
// DGV Header Names
dgvPerson.Columns[0].Name = " ID";
dgvPerson.Columns[1].Name = "First Name";
dgvPerson.Columns[2].Name = "Last Name";
dgvPerson.Columns[0].HeaderCell.Style.Font = new Font("Bold Tahoma", 11);
dgvPerson.Columns[1].HeaderCell.Style.Font = new Font("Bold Tahoma", 11);
dgvPerson.Columns[2].HeaderCell.Style.Font = new Font("Bold Tahoma", 11);
dgvPerson.Columns[0].HeaderCell.Style.ForeColor = Color.Blue;
dgvPerson.Columns[1].HeaderCell.Style.ForeColor = Color.Blue;
dgvPerson.Columns[2].HeaderCell.Style.ForeColor = Color.Blue;
dgvPerson.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvPerson.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvPerson.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
}
private void btnReturn_Click(object sender, EventArgs e)
{
Close();
frmStart fST = new frmStart();
fST.Show();
}
}
}
First let me say that using the TOOL from a VB.Net project was a BIG 4 hour mistake
Here is the code I used to capture the values in the DataGridView
private void dgvPerson_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int ID = 0;// Declare this top level
ID = Convert.ToInt32(dgvPerson.Rows[e.RowIndex].Cells[0].Value.ToString());
tbID.Text = ID.ToString();
tbFName.Text = dgvPerson.Rows[e.RowIndex].Cells[1].Value.ToString();
tbLName.Text = dgvPerson.Rows[e.RowIndex].Cells[2].Value.ToString();
}
Here is what was WRONG Visual Studio 2019 has two DataGridView Tools
One under All Windows Forms and one under Data (see attached screen shot)
I used the one under All Windows Form in the ToolBox hence my code FAILED
Use the DGV under Data in the ToolBox if your are working with C# and SQLite
I have a simple client registration form. I placed some textboxes next to a data grid view, so that I could add and update users. That was working fine and still does.
Recently, I have added a new windows form for client definition, so that when double-clicking a row a form with required field comes up that shows clients information and lets you change them. Clicking the "OK" button will save changes to the SQL database.
With the field beside the grid view, when I update a user info the grid view immediately gets updated and shows data, but when updating data with the new form, updates do not show in the grid view even if I double-click the row again. When I close the app and run it again I will see the updated data.
I have added an activation event for the main form to update the grid view with selecting data again from the database, but no success. This is the code that i am using for the update from side panel:
private void btnUpdate_Click(object sender, EventArgs e)
{
if (btnUpdate.Text == "Update")
{
txtUsername.Text = ClientsGridView.CurrentRow.Cells["Username"].Value.ToString();
txtPassword.Text = ClientsGridView.CurrentRow.Cells["Password"].Value.ToString();
txtUID.Text = ClientsGridView.CurrentRow.Cells["UID"].Value.ToString();
txtName.Text = ClientsGridView.CurrentRow.Cells["Name"].Value.ToString();
chkIsActive.Checked = (bool)ClientsGridView.CurrentRow.Cells["IsActive"].Value;
chkItemListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["ItemListAccess"].Value;
chkMaterialSumAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["MaterialSumAccess"].Value;
chkPartListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["PartListAccess"].Value;
chkPriceListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["PriceListAccess"].Value;
btnUpdate.Text = "Apply Update";
btnSubmit.Enabled = false;
txtUsername.ReadOnly = true;
}
else if (btnUpdate.Text == "Apply Update")
{
if (ClientFormValidation())
{
int id = Convert.ToInt32(ClientsGridView.CurrentRow.Cells["ID"].Value.ToString());
var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
if (SelectedUser.Count() == 1)
{
Client UpdatingClient = SelectedUser.Single();
UpdatingClient.Password = txtPassword.Text.Trim();
UpdatingClient.UID = txtUID.Text.Trim();
UpdatingClient.Name = txtName.Text.Trim();
UpdatingClient.IsActive = chkIsActive.Checked;
UpdatingClient.ItemListAccess = chkItemListAccess.Checked;
UpdatingClient.MaterialSumAccess = chkMaterialSumAccess.Checked;
UpdatingClient.PartListAccess = chkPartListAccess.Checked;
UpdatingClient.PriceListAccess = chkPriceListAccess.Checked;
ClientsContext.SubmitChanges();
}
ShowAll();
ClearClientForm();
btnUpdate.Text = "Update";
btnSubmit.Enabled = true;
txtUsername.ReadOnly = false;
}
}
}
and this is for Client definition form:
private void btnOK_Click(object sender, EventArgs e)
{
if(ISnewUser)
{
InsertNewClient();
}
else if(!ISnewUser)
{
UpdateClient();
}
this.Close();
}
private void UpdateClient()
{
if (ClientFormValidation())
{
var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
if (SelectedUser.Count() == 1)
{
Client UpdatingClient = SelectedUser.Single();
UpdatingClient.Password = txtPassword.Text.Trim();
UpdatingClient.UID = txtUID.Text.Trim();
UpdatingClient.Name = txtName.Text.Trim();
UpdatingClient.IsActive = chkUserActiveSatus.Checked;
UpdatingClient.ItemListAccess = chkItemListAccess.Checked;
UpdatingClient.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
UpdatingClient.PartListAccess = chkPartListAccess.Checked;
UpdatingClient.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
}
}
Can anyone tell me what is wrong with this code?
*var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
It is Iqueryable, apply .ToList() to fetch into memory and then patch the change.
Instead i suggest , use this,
var SelectedUser = (from Client in ClientsContext.Clients
where Client.ID == id
select Client).FirstOrDefault();
if(SelectedUser!=null){
SelectedUser.Password = txtPassword.Text.Trim();
SelectedUser.UID = txtUID.Text.Trim();
SelectedUser.Name = txtName.Text.Trim();
SelectedUser.IsActive = chkUserActiveSatus.Checked;
SelectedUser.ItemListAccess = chkItemListAccess.Checked;
SelectedUser.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
SelectedUser.PartListAccess = chkPartListAccess.Checked;
SelectedUser.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
else{
//write your logic
}*
I am leaving exception handling to you only.
i solved it myself,
i passed a Client object while initializing the client definition form.
so for updating i used exactly the same object not getting its parapeter and selecting it again from data base:
public frmClientDefinition(Client thisClient=null)
{
InitializeComponent();
if (thisClient!=null)
{
User = thisClient;
id = thisClient.ID;
ISnewUser = false;
txtName.Text = thisClient.Name;
txtUsername.Text = thisClient.Username;
txtPassword.Text = thisClient.Password;
txtDate.Text = thisClient.Date.ToString();
txtUID.Text = thisClient.UID;
chkUserActiveSatus.Checked = thisClient.IsActive;
chkItemListAccess.Checked = thisClient.ItemListAccess;
chkPartListAccess.Checked = thisClient.PartListAccess;
chkMaterialSummeryAccess.Checked = thisClient.MaterialSumAccess;
chkPriceListAcess.Checked = thisClient.PriceListAccess;
chkFullPriceListAccess.Checked = false;
chkOfficialRecieptAccess.Checked = false;
chkNonOfficialRecieptAccess.Checked = false;
chkAdvancedPriceControlsAccess.Checked = false;
chkFullPriceListSaveAccess.Checked = false;
chkOfficialRecieptSaveAccess.Checked = false;
chkNonOfficialRecieptSaveAccess.Checked = false;
txtUsername.ReadOnly = true;
}
txtDate.Text = DateTime.Now.ToString();
}
and for updating this snippet:
private void UpdateClient()
{
if (ClientFormValidation())
{
User.Password = txtPassword.Text.Trim();
User.UID = txtUID.Text.Trim();
User.Name = txtName.Text.Trim();
User.IsActive = chkUserActiveSatus.Checked;
User.ItemListAccess = chkItemListAccess.Checked;
User.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
User.PartListAccess = chkPartListAccess.Checked;
User.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
}
Hi I have one gridview on the left and I have Multiview pane on the right. Basically what I am trying to do is when the use click select in the gridview, the information of that row will display in the Multiview.
I have two view.
View 1 contains label saying please select row to view full details.
View 2 basically retrieving all the necessary data.
The problem is, in my view 2, I do allow user to update the data. When the user updates the data and save, the view will go back to its initial view. And when the user click on the same row, it will then display the updated information.
How can I do such that when they save the changes, the view will show the updated information?
I have tried putting updatepanel but it does not work too.
CODE BEHIND:
protected void Page_Load(object sender, EventArgs e)
{
xxBLL schBLL = new xxBLL ();
GVFBAcc.DataSource = schBLL.getInfo();
GVFBAcc.DataBind();
MainView.ActiveViewIndex = 1;
}
protected void GVFBAcc_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string Selectedid = GVFBAcc.SelectedRow.Cells[1].Text;//get user id
int selectedIdtoPass = Convert.ToInt32(Selectedid);
xxBLL getRecord = new xxBLL ();
addInfo InfoRetrieve = new addInfo ();
InfoRetrieve = getRecord.getDetail(selectedIdtoPass);
lbid.Text = Convert.ToString(InfoRetrieve .info_id1);
lbType.Text = InfoRetrieve .type;
lbName.Text = InfoRetrieve .name;
lbAbb.Text = InfoRetrieve .abb;
MainView.ActiveViewIndex = 0;
}
catch (Exception ex)
{
lbMessage.Visible = true;
lbMessage.Text = "Please select a Row.";
}
}
protected void editInfo_Click(object sender, ImageClickEventArgs e)
{
MainView.ActiveViewIndex = 0;
string cIcon = editInfo.ImageUrl;
if (cIcon.Equals("~/images/edit.png"))
{
editInfo.ImageUrl = "~/images/save.png";
lblEdit.Text = "";
tbName.Text = lbName.Text;
tbAbb.Text = lbAbb.Text;
tbtype.Text = lbType.Text;
lbName.Visible = false;
lbAbb.Visible = false;
lbType.Visible = true;
tbName.Visible = true;
tbAbb.Visible = true;
tbtype.Visible = false;
}
else if (cIcon.Equals("~/images/save.png"))
{
addInfo[] update = new addInfo[1];
int id = Convert.ToInt32(lbid.Text);
string name = tbName.Text;
string abb = tbAbb.Text;
addInfo updated = new addInfo(name, id, abb);
update[0] = updated;
xxBLL obj = new xxBLL ();
if (obj.updateDetail(update))
{
editInfo.ImageUrl = "~/images/edit.png";
lbName.Visible = true;
lbAbb.Visible = true;
lbType.Visible = true;
tbName.Visible = false;
tbAbb.Visible = false;
tbtype.Visible = false;
lblEdit.Text = "Saved";
lblEdit.ForeColor = Color.Green;
tbName.Text = lbName.Text;
tbAbb.Text = lbAbb.Text;
tbtype.Text = lbType.Text;
}
}
}
When the user updates the data and save, the view will go back to its initial view. And when the user click on the same row, it will then display the updated information. How can I do such that when they save the changes, the view will show the updated information?
or alternative How do i call the button click event at page load so that when the user clicks the save button, it will display the updated infomation
We have aspx page that is being used as a dialog box.
Page has ascx control which has Text box to search available users from oracle DB tables.
Every search click posts back to same control and renders search results.
If I click search and before response is back from server I close the dialog aspx page, then next time I try to open same dialog box it takes forever to render.
Please suggest what could be happening, going wrong?
Any help is highly appreciated
Here is the code
protected void UserListControl_PreRender(object sender, EventArgs e)
{
//set UI text
m_objTitle.Text = TITLE_LABEL;
//Set Properties of search
m_objSearchResults.CacheResults = true;
m_objSearchResults.RefreshCache = true;
m_objSearchResults.DoSearch = true;
m_objSearchResults.Pageable = true;
m_objSearchResults.NoRecordsMessage = NO_RECORDS_MSG;
m_objSearchResults.PageSize = 25;
m_objSearchResults.SearchType = m_sSearchType;
//Add items to the dropdown
if (m_objStatusDropDown.Items.FindByText(AVAIL_USER_TEXT) == null)
{
m_objStatusDropDown.Items.Add(AVAIL_USER_TEXT);
m_objStatusDropDown.Items.FindByText(AVAIL_USER_TEXT).Value = AVAIL_USER_VALUE;
}
if (m_objStatusDropDown.Items.FindByText(ALL_USER_TEXT) == null)
{
m_objStatusDropDown.Items.Add(ALL_USER_TEXT);
m_objStatusDropDown.Items.FindByText(ALL_USER_TEXT).Value = ALL_USER_VALUE;
}
if (m_objStatusDropDown.Items.FindByText(SEARCH_USER_TEXT) == null)
{
m_objStatusDropDown.Items.Add(SEARCH_USER_TEXT);
m_objStatusDropDown.Items.FindByText(SEARCH_USER_TEXT).Value = SEARCH_USER_VALUE;
}
if (this.Page.IsPostBack == false)
{
m_objStatusDropDown.SelectedValue = SEARCH_USER_VALUE;
}
if (IsPostBack)
{
try
{
m_objUserInstructionText.Text = "";
//add the DAO Parameters
string assignmentTypeSelected = Request.QueryString["AssignmentType"];
m_objSearchResults.DAOParams.Add("RequestType", Request.QueryString["RequestType"]);
m_objSearchResults.DAOParams.Add("AssignmentID", Request.QueryString["AssignmentID"]);
m_objSearchResults.DAOParams.Add("AssignmentType", assignmentTypeSelected);
m_objSearchResults.DAOParams["StatusFilter"] = m_objStatusDropDown.SelectedValue.ToUpper();
m_objSearchResults.DAOParams["Name"] = m_objSearchTextBox.Value.Trim();
if (null == SetApplCode(assignmentTypeSelected))
{
throw new ApplicationException("Invalid Assignment Type.");
}
else
{
m_objSearchResults.DAOParams["ApplCode"] = SetApplCode(assignmentTypeSelected).ToUpper();
}
//add searchControl
m_objListPH.Controls.Add(m_objSearchResults);
// Get the values from the ResultsForm
string sRecordsDisplayed = m_objSearchResults.RecordsDisplayed;
string sTableWidth = m_objSearchResults.TableWidth;
bool bPageable = m_objSearchResults.Pageable;
int iCurrentPageIndex = m_objSearchResults.CurrentPageIndex;
int iPageSize = m_objSearchResults.PageSize;
int iRecordCount = m_objSearchResults.RecordCount;
int iEndRecord = m_objSearchResults.EndRecord;
// Create the html if we are paging data
m_objNavigation.Visible = bPageable;
m_objNavigation.DisplayViewAllButton = false;
m_objNavigation.PageSize = iPageSize;
m_objNavigation.Count = iRecordCount;
m_objNavigation.ItemsDisplayText = "Users";
m_objNavigation.CurrentPage = iCurrentPageIndex + 1;
}
catch (ApplicationException ex)
{
m_objInvalidAssignTypeErr.Text = ex.Message;
m_objUserInstructionText.Text = "";
}
}
}
I have a old time sheet application with historical data, the hr would like to view the old data once in a while, so i was given the task to build an c# application that would do so. first the user selects a paygroup drop down, chooses a pay group, based on the paygroup select the employees drop down get populated, then i have two text box one containing the min date and another containing you guessed it right a max date, Then i have two datetimepickers fromdate and to date. the datetimepicker gets its value from the mindate date box and max date text box, after all the items are selected the user clicks run report and the report is generated.
For a visual please click this -> picture
My Question is I want to set the visibility of the datetimepickers to false if there are no dates available like in this -> picture as you can see the dates dont change because the datetimepickers can't set itself equal to an empty string so to work around that i just want the user to not even see the datetimepickers
My Code that i tried:
private void mindateset() // fill the listbox of values of mindate and maxdate
{
if (Employee.SelectedValue != null)
{
if (Employee.SelectedValue.ToString().Trim().Length > 0)
{
try
{
using (MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
{
timepunchnew = new EtimeHistoryDataSet();
connection.Open();
using (MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT MIN(TransDate) AS mindate, MAX(TransDate) AS maxdate FROM dbo.EtimePunchDetail WHERE (EmpID = #empid)", connection))
{
MSSQL.SqlParameter myminparam = new MSSQL.SqlParameter();
myminparam.Direction = ParameterDirection.Input;
myminparam.ParameterName = "#empid";
myminparam.Value = Employee.SelectedValue;
command.Parameters.Add(myminparam);
MSSQL.SqlDataAdapter myadapter = new System.Data.SqlClient.SqlDataAdapter();
myadapter.SelectCommand = command;
myadapter.Fill(timepunchnew, "Mindate");
AvailableMin.DataSource = timepunchnew.Mindate;
AvailableMin.DisplayMember = "mindate";
AvailableMax.DataSource = timepunchnew.Mindate;
AvailableMax.DisplayMember = "maxdate";
FromDate.MinDate = DateTime.Parse(AvailableMin.Text);
FromDate.Value = FromDate.MinDate;
if (FromDate.Value != FromDate.MinDate)
{
if (DialogResult.OK == MessageBox.Show("The Selected User Does Not Have Any FromDate"))
{
FromDate.Visible = false;
}
else
{
FromDate.Value = FromDate.MinDate;
FromDate.Visible = true;
}
}
ToDate.MaxDate = DateTime.Parse(AvailableMax.Text);
ToDate.Value = ToDate.MaxDate;
if (ToDate.Value != ToDate.MaxDate)
if (DialogResult.OK == MessageBox.Show("The Selected User Does Not Have Any FromDate"))
{
ToDate.Visible = false;
}
else
{
ToDate.Value = ToDate.MinDate;
ToDate.Visible = true;
}
}
}
ANY HELP WITH THIS WILL BE APPRECIATED, THIS IS THE LAST STEP IN MY PROJECT
I created two textboxes and placed it over the datetimepicker value and make it visible if there is not date available from the listbox :)
private void AvailableMin_SelectedIndexChanged(object sender, EventArgs e)
{
if (AvailableMin.Text == "")
{
textBox2.Visible = true;
textBox2.Text = "There are no to dates available for this particular user";
}
else
{
textBox2.Visible = false;
}
}
private void AvailableMax_SelectedIndexChanged(object sender, EventArgs e)
{
if (AvailableMax.Text == "")
{
textBox1.Visible = true;
textBox1.Text = "There are no to dates available for this particular user";
}
else
{
textBox1.Visible = false;
}
}