I have this block of code which worked at the prior version (VS 2010, older RadGrid control). Now I upgraded to VS 2013 and use RadGrid control in version 2013.3.114.45, I can't figure out why I can't get the "ApplicationId" value from e.item.
Please see code below:
private void LoadData()
{
if (RadGrid1.Items.Count > 0) RadGrid1.DataSource = new Object[0]; //If Academic year is selected
if (editAcademicYear.SelectedValue !="Select One")
{
var academicyear = (from ay in context.AcademicYears
where ay.Name == editAcademicYear.SelectedValue
select ay).First();
yearID = academicyear.AcademicYearID;
} if (rbLName.Checked)
{
if (editSName.Text.Length > 0)
{
if (yearID > 0)
{
application = from s in context.Applications.Include("AcademicYear")
where s.LastName.StartsWith(editSName.Text.Trim()) &&
s.AcademicYear.AcademicYearID == yearID
orderby s.LastName, s.FirstName
select s;
}
else
{
application = from s in context.Applications
where s.LastName.StartsWith(editSName.Text.Trim())
orderby s.LastName, s.FirstName
select s;
}
ShowApps(application, application.Count()); //Show data to RadGrid1 for selection. }
else
{
lblmissing.Visible = true;
lblmissing.Text = "Please enter the last name.";
return;
}
}
}
//question: how can I get the value for dataItem below? What is wrong here?
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
LoadData();
//from debugging, I saw "application" value, but I did not see value
from RadGrid1 or its "items". try
{
if (e.Item.ItemIndex > -1)
{
var dataItem = e.Item as GridDataItem; //dataItem has no value here
string appid = dataItem["ApplicationId"].Text; //therefore, appid has no value
Response.Redirect("DisplayApp.aspx?appid=" + appid);
}
}
catch (Exception ex)
{
logger.ErrorException("Could not get appid from the grid row", ex);
lblMessage.Visible = true;
RadGrid1.Visible = false;
lblMessage.Text = "<b>Error exists in the grid level. Please contact the Care Tech Support.</b>";
}
}
I have spent a few hours searching, the site is in production, but just can't get the "appid" of the selected row to display the detail page. Your quick response is much appreciated.
Thanks in advance!
Please see code below:
private void LoadData()
{
if (RadGrid1.Items.Count > 0) RadGrid1.DataSource = new Object[0]; //If Academic year is selected
if (editAcademicYear.SelectedValue !="Select One")
{
var academicyear = (from ay in context.AcademicYears
where ay.Name == editAcademicYear.SelectedValue
select ay).First();
yearID = academicyear.AcademicYearID;
} if (rbLName.Checked)
{
if (editSName.Text.Length > 0)
{
if (yearID > 0)
{
application = from s in context.Applications.Include("AcademicYear")
where s.LastName.StartsWith(editSName.Text.Trim()) &&
s.AcademicYear.AcademicYearID == yearID
orderby s.LastName, s.FirstName
select s;
}
else
{
application = from s in context.Applications
where s.LastName.StartsWith(editSName.Text.Trim())
orderby s.LastName, s.FirstName
select s;
}
ShowApps(application, application.Count()); //Show data to RadGrid1 for selection. }
else
{
lblmissing.Visible = true;
lblmissing.Text = "Please enter the last name.";
return;
}
}
}
//question: how can I get the value for dataItem below? What is wrong here?
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
LoadData();
//from debugging, I saw "application" value, but I did not see value
from RadGrid1 or its "items". try
{
if (e.Item.ItemIndex > -1)
{
var dataItem = e.Item as GridDataItem; //dataItem has no value here
string appid = dataItem["ApplicationId"].Text; //therefore, appid has no value
Response.Redirect("DisplayApp.aspx?appid=" + appid);
}
}
catch (Exception ex)
{
logger.ErrorException("Could not get appid from the grid row", ex);
lblMessage.Visible = true;
RadGrid1.Visible = false;
lblMessage.Text = "<b>Error exists in the grid level. Please contact the Care Tech Support.</b>";
}
}
I have spent a few hours searching, the site is in production, but just can't get the "appid" of the selected row to display the detail page. Your quick response is much appreciated.
Thanks in advance!