I added Employee LastName and First name to a combobox which is working, Eg. LastName, FirstName.. The value should be set as EmpID so that when I'm selecting an Item, EmpId will be return as value
conn.Open();
using (SqlCommand cmd = new SqlCommand("Select (LastName + ', ' + FirstName) AS Employee,EmpID from Employee ", conn))
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
ListItem ComboItem = new ListItem();
ComboItem.Text = rdr["Employee"].ToString();
//ComboItem.Value = rdr["EmpID"].ToString();
ComboItem.Value = rdr["EmpID"].ToString() ;
GrpEmpCBox.Items.Add(ComboItem);
//GrpEmpCBox.Items.Add(rdr["Employee"].ToString());
}
}
But when I'm getting the value of it returns null.
private void btnRunReport_Click(object sender, EventArgs e)
{
EmployeeTimecardReport rptEmpTimecard = new EmployeeTimecardReport();
rptEmpTimecard.Employee = GrpEmpCBox.SelectedValue.ToString(); //<--- this returns null
}
is this possible? I'm trying not to use databinding
my combobox properties:
DataSource: none
DisplayMember: none
Value Member: none
DropDownStyle: DropDownList