How can i shorter below codes than before? i need short and simple method: i dont want to use foreach loop because i have one value.
public partial class Test : System.Web.UI.Page
{
StaffManagementEntities staffContext;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadStaffPersonel();
}
}
void LoadStaffPersonel()
{
int selectedDepartman = Convert.ToInt32(Request.QueryString["SelectedDepartmanID"]);
string name="";
using (staffContext = new StaffManagementEntities())
{
var DepartmanName = from d in staffContext.Departman
where d.ID == selectedDepartman
select d;
foreach (Departman d in DepartmanName)
{
name = d.Name;
}
ObjectResult<StaffsPersonel> personalData = staffContext.GetPersonelData(name);
gvPersonel.DataSource = personalData;
gvPersonel.DataBind();
}
}
}
How to use string value instead of " var DepartmanName "