public partial class login_activity_survey : PageHelperBase
{
protected System.Web.UI.WebControls.Label LblAnketSoru;
protected System.Web.UI.WebControls.TextBox TxtFreeText;
protected System.Web.UI.WebControls.CheckBoxList ChkSecimler;
protected System.Web.UI.WebControls.ListItem LiSecim;
protected System.Web.UI.WebControls.RadioButtonList RdSecimler;
protected System.Web.UI.WebControls.Literal Literalim;
protected void Page_Load(object sender, EventArgs e)
{
string AnketId = ConfigurationManager.AppSettings["AnketId"].ToString();
GenerateSurvey(AnketId, plc);
}
void GenerateSurvey(string AnketId, System.Web.UI.WebControls.PlaceHolder plch)
{
var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName)));
var AnketSoru = from p in db.new_survey_questions
orderby p.new_rank
select new { p.new_survey_questionid, p.new_question_text, p.new_question_type, p.new_rank, p.new_min_enumerator, p.new_max_enumerator };
HtmlTable tbl = new HtmlTable();
tbl.CellPadding = 2;
tbl.CellSpacing = 3;
HtmlTableRow r = new HtmlTableRow();
HtmlTableCell c = new HtmlTableCell();
c.InnerHtml = "<h3>İMMİB</h3>";
c.ColSpan = 2;
c.Align = "center";
r.Cells.Add(c);
tbl.Border = 1;
tbl.ID = "Survey_Inner";
tbl.Rows.Add(r);
c = new HtmlTableCell();
r = new HtmlTableRow();
c.ColSpan = 2;
c.InnerHtml = "<h4>EĞİTİM DEĞERLENDİRME FORMU</h4>";
c.Align = "center";
r.Cells.Add(c);
tbl.Rows.Add(r);
foreach (var item in AnketSoru)
{
r = new HtmlTableRow();
c = new HtmlTableCell();
c.InnerHtml = item.new_question_text.ToString();
r.Cells.Add(c);
switch (item.new_question_type.ToString())
{
case "2": //FreeText
c = new HtmlTableCell();
TxtFreeText = new TextBox();
TxtFreeText.ID = "Txt_" + item.new_survey_questionid.ToString();
TxtFreeText.TextMode = TextBoxMode.MultiLine;
TxtFreeText.Width = 300;
TxtFreeText.Height = 50;
TxtFreeText.EnableViewState = true;
c.Controls.Add(TxtFreeText);
break;
case "3": //CheckBox
c.ColSpan = 2;
var choises = from c1 in db.new_survey_question_choices
where c1.new_survey_questionid == item.new_survey_questionid
select c1;
ChkSecimler = new CheckBoxList();
ChkSecimler.ID = "Chkl_" + item.new_survey_questionid.ToString();
ChkSecimler.RepeatDirection = RepeatDirection.Horizontal;
ChkSecimler.RepeatColumns = 2;
ChkSecimler.Attributes.Add("class", "ChkCss");
foreach (var ck in choises)
{
LiSecim = new ListItem();
LiSecim.Text = ck.new_name;
ChkSecimler.Items.Add(LiSecim);
}
c.Controls.Add(ChkSecimler);
break;
case "4": //Enumeration RadioButton
c = new HtmlTableCell();
RdSecimler = new RadioButtonList();
RdSecimler.ID = "Rdl_" + item.new_survey_questionid.ToString();
RdSecimler.RepeatDirection = RepeatDirection.Horizontal;
RdSecimler.CellPadding = 2;
c.Align = "center";
RdSecimler.Attributes.Add("class", "TblCss");
for (int i = Convert.ToInt32(item.new_min_enumerator); i <= Convert.ToInt32(item.new_max_enumerator); i++)
{
LiSecim = new ListItem();
LiSecim.Text = i.ToString();
RdSecimler.Items.Add(LiSecim);
}
c.Controls.Add(RdSecimler);
break;
default:
break;
}
r.Cells.Add(c);
tbl.Rows.Add(r);
}
plch.Controls.Add(tbl);
}
и
void SaveAnswers(Guid ContactId, Guid ActivityAttendee, Guid QuestionId, string FreeTextCevap)
{
var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName)));
Xrm.new_survey_answer answer = new Xrm.new_survey_answer();
answer.new_participantid = ContactId;
answer.new_activity_attendeeid = ActivityAttendee;
answer.new_survey_questionid = QuestionId;
answer.new_answer_text = FreeTextCevap;
try
{
db.AddTonew_survey_answers(answer);
db.SaveChanges();
}
catch (Exception)
{
throw;
}
}
void SaveAnswers(Guid ContactId, Guid ActivityAttendee, Guid QuestionId, int EnumarationCevap)
{
var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName)));
Xrm.new_survey_answer answer = new Xrm.new_survey_answer();
answer.new_participantid = ContactId;
answer.new_activity_attendeeid = ActivityAttendee;
answer.new_survey_questionid = QuestionId;
answer.new_answer_numeric_value = EnumarationCevap;
try
{
db.AddTonew_survey_answers(answer);
db.SaveChanges();
}
catch (Exception)
{
throw;
}
}
void SaveAnswers(Guid ContactId, Guid ActivityAttendee, Guid QuestionId, Guid CheckboxCevap)
{
var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName)));
Xrm.new_survey_answer answer = new Xrm.new_survey_answer();
answer.new_participantid = ContactId;
answer.new_activity_attendeeid = ActivityAttendee;
answer.new_survey_questionid = QuestionId;
answer.new_survey_question_choiceid = CheckboxCevap;
try
{
db.AddTonew_survey_answers(answer);
db.SaveChanges()
}
catch (Exception)
{
throw;
}
}
и
protected void SurveySubmit_Click(object sender, EventArgs e)
{
string AttendeeId = Request.QueryString.Get("atId") != null ? Request.QueryString.Get("atId").ToString() : string.Empty;
Guid EgitimKatilimcisi = new Guid("9163DA6E-3E97-E011-8A8F-001517557A34");
foreach (Control c in plc.Controls)
{
System.Web.UI.HtmlControls.HtmlTable Survey_Inner = (System.Web.UI.HtmlControls.HtmlTable)c.FindControl("Survey_Inner");
foreach (System.Web.UI.HtmlControls.HtmlTableRow r in Survey_Inner.Rows)
{
foreach (Control ctr in r.Cells)
{
foreach (Control ct in ctr.Controls)
{
if (ct.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
string TextCevap = ((System.Web.UI.WebControls.TextBox)ct).Text;
string deger = ct.ID.ToString();
Guid QuestionId = new Guid(deger.Substring(4));
SaveAnswers(this._PortalUserHelper.UserProxy.ContactId, EgitimKatilimcisi, QuestionId, TextCevap);
}
else if (ct.GetType().ToString() == "System.Web.UI.WebControls.RadioButtonList")
{
int Enumaration = Convert.ToInt32(((System.Web.UI.WebControls.RadioButtonList)ct).SelectedValue);
string deger = ct.ID.ToString();
Guid QuestionId = new Guid(deger.Substring(4));
SaveAnswers(this._PortalUserHelper.UserProxy.ContactId, EgitimKatilimcisi, QuestionId, Enumaration);
}
else if (ct.GetType().ToString() == "System.Web.UI.WebControls.CheckBoxList")
{
int Cevap = Convert.ToInt32(((System.Web.UI.WebControls.CheckBoxList)ct).SelectedItem);
string deger = ct.ID.ToString();
Guid QuestionId = new Guid(deger.Substring(4));
SaveAnswers(this._PortalUserHelper.UserProxy.ContactId, EgitimKatilimcisi, QuestionId, Cevap);
}
У меня проблема с этой секундой, если для чекбокса все остальные (radiobutton и freetxt) в порядке.
Строка 250: else if (ct.GetType (). ToString () == "System.Web.UI.WebControls.CheckBoxList")
Строка 251: {
Строка 252: int Cevap = Convert.ToInt32 (((System.Web.UI.WebControls.CheckBoxList) ct) .SelectedItem);
Строка 253:
Строка 254: строка deger = ct.ID.ToString ();
Проблема в линии 252
Ошибка сервера в приложении '/'.
'System.Web.UI.WebControls.ListItem' türündeki nesne 'System.IConvertible' türüne atılamadı.
Описание: во время выполнения текущего веб-запроса произошло необработанное исключение. Пожалуйста, просмотрите трассировку стека для получения дополнительной информации об ошибке и о том, где она возникла в коде.
Сведения об исключении: System.InvalidCastException: 'System.Web.UI.WebControls.ListItem' türündeki nesne 'System.IConvertible' türüne atılamadı.
У меня есть флажок, я хочу взять все выбранные предметы и записать в crm. любая помощь?