Telerik RadGrid 问题:“Telerik.Web.UI.GridInsertionObject”不包含名称为“XXX”的属性
在过去的几个小时里,我一直在尝试找到以下问题的解决方法,但没有成功。我在互联网上找到了许多可能的解决方案,但没有一个能解决我的问题。我还在 Telerik 官方论坛上发布了同样的问题,尽管我几乎可以肯定我不会得到他们的回复。
当我想将数据插入空数据源时,就会出现问题。我已经能够找到 RadComboBox 的解决方法,但不能找到文本框的解决方法。显示的错误是:“DataBinding:‘Telerik.Web.UI.GridInsertionObject’不包含名为‘OpciPrioritet’的属性。”
以下是代码:
.ascx(RadGrid 所需):
<table>
<tr>
<td>
Nadređeni ticket:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbNadredeniTicket" AppendDataBoundItems="true" runat="server"
Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Prijavio:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbPrijavio" AppendDataBoundItems="true" runat="server"
Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Asset:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbAsset" AppendDataBoundItems="true" runat="server" Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Opći prioritet:
</td>
<td>
<asp:TextBox ID="txtOpciPrioritet" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OpciPrioritet") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Tip:
</td>
<td>
<telerik:RadComboBox ID="rcbTip" runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Status:
</td>
<td>
<telerik:RadComboBox ID="rcbStatus" runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Datum prijave:
</td>
<td>
<asp:TextBox ID="txtDatumPrijave" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumPrijave") %>'></asp:TextBox>
</td>
<td>
Vrsta prijave:
</td>
<td>
<telerik:RadComboBox ID="rcbVrstaPrijave" Text='<%# DataBinder.Eval(Container, "DataItem.VrstaPrijave") %>'
runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Prioritet:
</td>
<td>
<telerik:RadComboBox ID="rcbPrioritet" Text='<%# DataBinder.Eval(Container, "DataItem.Prioritet") %>'
runat="server">
</telerik:RadComboBox>
</td>
<td>
Deadline:
</td>
<td>
<asp:TextBox ID="txtDeadline" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumDo") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Opis:
</td>
<td colspan="3">
<asp:TextBox ID="txtOpis" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
Text='<%# DataBinder.Eval(Container, "DataItem.Opis") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Zatvoren ticket:
</td>
<td>
<asp:CheckBox ID="chkZatvoren" runat="server" Checked='<%# CheckNull(DataBinder.Eval(Container, "DataItem.Zatvoren")) %>' />
</td>
</tr>
<tr>
<td>
Opis zatvorenog ticketa:
</td>
<td colspan="3">
<asp:TextBox ID="txtOpisZatvorenog" runat="server" TextMode="MultiLine" Width="455px"
Height="200px" Text='<%# DataBinder.Eval(Container, "DataItem.OpisZatvoren") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Bilješke:
</td>
<td colspan="3">
<asp:TextBox ID="txtBiljeske" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
Text='<%# DataBinder.Eval(Container, "DataItem.Biljeske") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnUpdate" Text="Spremi" runat="server" CommandName="Update" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'>
</asp:Button>
<asp:Button ID="btnInsert" Text="Spremi" runat="server" CommandName="PerformInsert"
Visible='<%# DataItem is Telerik.Web.UI.GridInsertionObject %>'></asp:Button>
<asp:Button ID="btnCancel" Text="Odustani" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</td>
</tr>
.aspx.cs(仅需要的代码片段):
protected void gvTicketi_ItemDataBound(object sender, GridItemEventArgs e)
{
int idFirma = Convert.ToInt16(Request.QueryString["idt"]);
if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode )
{
GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
TSEntities db = new TSEntities();
Ticket ticket = new Ticket();
TicketAsset ticketAsset = new TicketAsset();
RadComboBox rcbTip = (RadComboBox)userControl.FindControl("rcbTip");
rcbTip.Items.Add(new RadComboBoxItem("Incident"));
rcbTip.Items.Add(new RadComboBoxItem("Reklamacija"));
rcbTip.Items.Add(new RadComboBoxItem("Nova funkcionalnost"));
rcbTip.DataBind();
rcbTip.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Tip') %>'";
RadComboBox rcbStatus = (RadComboBox)userControl.FindControl("rcbStatus");
rcbStatus.Items.Add(new RadComboBoxItem("New"));
rcbStatus.Items.Add(new RadComboBoxItem("U radu"));
rcbStatus.Items.Add(new RadComboBoxItem("On hold"));
rcbStatus.Items.Add(new RadComboBoxItem("Pending"));
rcbStatus.Items.Add(new RadComboBoxItem("Scheduled"));
rcbStatus.Items.Add(new RadComboBoxItem("Canceled"));
rcbStatus.Items.Add(new RadComboBoxItem("Completed"));
rcbStatus.DataBind();
rcbStatus.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Status') %>'";
RadComboBox rcbVrstaPrijave = (RadComboBox)userControl.FindControl("rcbVrstaPrijave");
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Usmeno"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Telefon"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("E-mail"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Web"));
rcbVrstaPrijave.DataBind();
rcbVrstaPrijave.Text = "'<%# DataBinder.Eval(Container, 'DataItem.VrstaPrijave') %>'";
RadComboBox rcbPrioritet = (RadComboBox)userControl.FindControl("rcbPrioritet");
rcbPrioritet.Items.Add(new RadComboBoxItem("Low"));
rcbPrioritet.Items.Add(new RadComboBoxItem("Normal"));
rcbPrioritet.Items.Add(new RadComboBoxItem("High"));
rcbPrioritet.Items.Add(new RadComboBoxItem("Odmah"));
rcbPrioritet.DataBind();
rcbPrioritet.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Prioritet') %>'";
RadComboBox rcbNadredeniTicket = (RadComboBox)userControl.FindControl("rcbNadredeniTicket");
var nadredenTicketList = (from t in db.Ticket
select t).ToList();
if (nadredenTicketList.Count > 0)
{
rcbNadredeniTicket.DataSource = from t in nadredenTicketList
where t.idFirma == idFirma && t.Zatvoren == false
select new { t.idTicket, t.idNadredeniTicket, OpisTicketa = t.idTicket + " - " + t.Opis };
rcbNadredeniTicket.DataTextField = "OpisTicketa";
rcbNadredeniTicket.DataValueField = "idTicket";
rcbNadredeniTicket.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idNadredeniTicket') %>'";
}
rcbNadredeniTicket.Items.Add(new RadComboBoxItem("Bez nadređenog ticketa", "0"));
rcbNadredeniTicket.DataBind();
RadComboBox rcbPrijavio = (RadComboBox)userControl.FindControl("rcbPrijavio");
rcbPrijavio.DataSource = from k in db.Kontakt
where k.idFirma == idFirma
select new { k.idKontakt, kontaktNaziv = k.Ime + " " + k.Prezime };
rcbPrijavio.Items.Add(new RadComboBoxItem("Bez kontakta", "0"));
rcbPrijavio.DataTextField = "kontaktNaziv";
rcbPrijavio.DataValueField = "idKontakt";
rcbPrijavio.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idKontakt') %>'";
rcbPrijavio.DataBind();
RadComboBox rcbAsset = (RadComboBox)userControl.FindControl("rcbAsset");
var assetList = (from a in db.Asset
where a.idFirma == idFirma
select a).ToList();
if (assetList.Count > 0)
{
var assets = from a in assetList
where a.idFirma == idFirma
select new { a.idAsset, Naziv = a.Naziv + " (" + a.Kontakt.Ime + " " + a.Kontakt.Prezime + ")" };
rcbAsset.DataSource = assets;
rcbAsset.DataTextField = "Naziv";
rcbAsset.DataValueField = "idAsset";
rcbAsset.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Naziv') %>'";
rcbAsset.Items.Add(new RadComboBoxItem("Bez pridruženog asseta", "0"));
rcbAsset.DataBind();
}
if (!e.Item.OwnerTableView.IsItemInserted)
{
int idTicket = Convert.ToInt32(editFormItem.GetDataKeyValue("idTicket"));
ticket = db.Ticket.SingleOrDefault(t => t.idTicket == idTicket);
string tip = ticket.Tip;
rcbTip.Items.FindItemByText(tip).Selected = true;
string status = ticket.Status;
rcbStatus.Items.FindItemByText(status).Selected = true;
string vrstaPrijave = ticket.VrstaPrijave;
rcbVrstaPrijave.Items.FindItemByText(vrstaPrijave).Selected = true;
string prioritet = ticket.Prioritet;
rcbPrioritet.Items.FindItemByText(prioritet).Selected = true;
int kontakt = Convert.ToInt32(ticket.idKontakt);
if (ticket.idKontakt == null)
{
rcbPrijavio.Items.FindItemByValue("0").Selected = true;
}
else
{
rcbPrijavio.Items.FindItemByValue(kontakt.ToString()).Selected = true;
}
int nadredeniTicket = Convert.ToInt32(ticket.idNadredeniTicket);
if (ticket.idNadredeniTicket == null)
{
rcbNadredeniTicket.Items.FindItemByValue("0").Selected = true;
}
else
{
rcbNadredeniTicket.Items.FindItemByValue(nadredeniTicket.ToString()).Selected = true;
}
var ticketAssetCount = from ta in db.TicketAsset
where ta.idTicket == idTicket
select ta;
if (ticketAssetCount.Count() > 0)
{
ticketAsset = db.TicketAsset.SingleOrDefault(ta => ta.idTicket == idTicket);
int asset = Convert.ToInt32(ticketAsset.idAsset);
rcbAsset.Items.FindItemByValue(asset.ToString()).Selected = true;
}
else
{
rcbAsset.Items.FindItemByValue("0").Selected = true;
}
}
else if (e.Item.OwnerTableView.IsItemInserted)
{
var newVals = new System.Collections.Specialized.ListDictionary();
newVals["OpciPrioritet"] = string.Empty;
e.Item.OwnerTableView.InsertItem(newVals);
}
}
}
.aspx:
<telerik:RadGrid ID="gvTicketi" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
onneeddatasource="gvTicketi_NeedDataSource"
onitemdatabound="gvTicketi_ItemDataBound"
oninsertcommand="gvTicketi_InsertCommand"
onupdatecommand="gvTicketi_UpdateCommand">
<MasterTableView DataKeyNames="idTicket" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings AddNewRecordText="Dodaj novi ticket" RefreshText="Prikaži sve tickete" />
<Columns>
<telerik:GridBoundColumn UniqueName="idTicket" HeaderText="Ticket" DataField="idTicket">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="idKontakt" HeaderText="Kontakt" DataField="idKontakt">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="idManager" HeaderText="Manager" DataField="idManager">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Opis" HeaderText="Opis" DataField="Opis">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="TicketNumber" HeaderText="Broj ticketa" DataField="TicketNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="DatumPrijave" HeaderText="Datum prijave" DataField="DatumPrijave" DataFormatString="{0:dd.MM.yyyy.}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="VrstaPrijave" HeaderText="Vrsta prijave" DataField="VrstaPrijave">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tip" HeaderText="Tip" DataField="Tip">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Status" HeaderText="Status" DataField="Status">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Prioritet" HeaderText="Prioritet" DataField="Prioritet">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="OpciPrioritet" HeaderText="Opći prioritet" DataField="OpciPrioritet">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Deadline" HeaderText="Deadline" DataField="DatumDo" DataFormatString="{0:dd.MM.yyyy.}">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="Zatvoren" HeaderText="Zatvoren" DataField="Zatvoren">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
ConfirmDialogType="RadWindow" ConfirmText="Brisanje ticketa!" />
</Columns>
<EditFormSettings UserControlName="UserControls/TicketUserControl.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
我真的希望你们能够帮助我,所以任何帮助将不胜感激!
I've been trying to find the workaround for the following problem for the last couple of hours, but without any success. I've found many of the possible solutions on the Internet, but none of them was solution to my problem. I've also posted the same question on official Telerik's forum even though I'm almost sure that I'll get no response from them.
The problem occurs when I want to insert data into empty datasource. I've been able to find workarounds for RadComboBoxes, but not for the Textboxes. The error that is displayed is: "DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'OpciPrioritet'."
Here is the code:
.ascx (needed for RadGrid):
<table>
<tr>
<td>
Nadređeni ticket:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbNadredeniTicket" AppendDataBoundItems="true" runat="server"
Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Prijavio:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbPrijavio" AppendDataBoundItems="true" runat="server"
Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Asset:
</td>
<td colspan="3">
<telerik:RadComboBox ID="rcbAsset" AppendDataBoundItems="true" runat="server" Width="455px">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Opći prioritet:
</td>
<td>
<asp:TextBox ID="txtOpciPrioritet" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OpciPrioritet") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Tip:
</td>
<td>
<telerik:RadComboBox ID="rcbTip" runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Status:
</td>
<td>
<telerik:RadComboBox ID="rcbStatus" runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Datum prijave:
</td>
<td>
<asp:TextBox ID="txtDatumPrijave" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumPrijave") %>'></asp:TextBox>
</td>
<td>
Vrsta prijave:
</td>
<td>
<telerik:RadComboBox ID="rcbVrstaPrijave" Text='<%# DataBinder.Eval(Container, "DataItem.VrstaPrijave") %>'
runat="server">
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
Prioritet:
</td>
<td>
<telerik:RadComboBox ID="rcbPrioritet" Text='<%# DataBinder.Eval(Container, "DataItem.Prioritet") %>'
runat="server">
</telerik:RadComboBox>
</td>
<td>
Deadline:
</td>
<td>
<asp:TextBox ID="txtDeadline" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DatumDo") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Opis:
</td>
<td colspan="3">
<asp:TextBox ID="txtOpis" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
Text='<%# DataBinder.Eval(Container, "DataItem.Opis") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Zatvoren ticket:
</td>
<td>
<asp:CheckBox ID="chkZatvoren" runat="server" Checked='<%# CheckNull(DataBinder.Eval(Container, "DataItem.Zatvoren")) %>' />
</td>
</tr>
<tr>
<td>
Opis zatvorenog ticketa:
</td>
<td colspan="3">
<asp:TextBox ID="txtOpisZatvorenog" runat="server" TextMode="MultiLine" Width="455px"
Height="200px" Text='<%# DataBinder.Eval(Container, "DataItem.OpisZatvoren") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
Bilješke:
</td>
<td colspan="3">
<asp:TextBox ID="txtBiljeske" runat="server" TextMode="MultiLine" Width="455px" Height="200px"
Text='<%# DataBinder.Eval(Container, "DataItem.Biljeske") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnUpdate" Text="Spremi" runat="server" CommandName="Update" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'>
</asp:Button>
<asp:Button ID="btnInsert" Text="Spremi" runat="server" CommandName="PerformInsert"
Visible='<%# DataItem is Telerik.Web.UI.GridInsertionObject %>'></asp:Button>
<asp:Button ID="btnCancel" Text="Odustani" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</td>
</tr>
.aspx.cs (only the needed code snippet):
protected void gvTicketi_ItemDataBound(object sender, GridItemEventArgs e)
{
int idFirma = Convert.ToInt16(Request.QueryString["idt"]);
if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode )
{
GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
TSEntities db = new TSEntities();
Ticket ticket = new Ticket();
TicketAsset ticketAsset = new TicketAsset();
RadComboBox rcbTip = (RadComboBox)userControl.FindControl("rcbTip");
rcbTip.Items.Add(new RadComboBoxItem("Incident"));
rcbTip.Items.Add(new RadComboBoxItem("Reklamacija"));
rcbTip.Items.Add(new RadComboBoxItem("Nova funkcionalnost"));
rcbTip.DataBind();
rcbTip.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Tip') %>'";
RadComboBox rcbStatus = (RadComboBox)userControl.FindControl("rcbStatus");
rcbStatus.Items.Add(new RadComboBoxItem("New"));
rcbStatus.Items.Add(new RadComboBoxItem("U radu"));
rcbStatus.Items.Add(new RadComboBoxItem("On hold"));
rcbStatus.Items.Add(new RadComboBoxItem("Pending"));
rcbStatus.Items.Add(new RadComboBoxItem("Scheduled"));
rcbStatus.Items.Add(new RadComboBoxItem("Canceled"));
rcbStatus.Items.Add(new RadComboBoxItem("Completed"));
rcbStatus.DataBind();
rcbStatus.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Status') %>'";
RadComboBox rcbVrstaPrijave = (RadComboBox)userControl.FindControl("rcbVrstaPrijave");
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Usmeno"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Telefon"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("E-mail"));
rcbVrstaPrijave.Items.Add(new RadComboBoxItem("Web"));
rcbVrstaPrijave.DataBind();
rcbVrstaPrijave.Text = "'<%# DataBinder.Eval(Container, 'DataItem.VrstaPrijave') %>'";
RadComboBox rcbPrioritet = (RadComboBox)userControl.FindControl("rcbPrioritet");
rcbPrioritet.Items.Add(new RadComboBoxItem("Low"));
rcbPrioritet.Items.Add(new RadComboBoxItem("Normal"));
rcbPrioritet.Items.Add(new RadComboBoxItem("High"));
rcbPrioritet.Items.Add(new RadComboBoxItem("Odmah"));
rcbPrioritet.DataBind();
rcbPrioritet.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Prioritet') %>'";
RadComboBox rcbNadredeniTicket = (RadComboBox)userControl.FindControl("rcbNadredeniTicket");
var nadredenTicketList = (from t in db.Ticket
select t).ToList();
if (nadredenTicketList.Count > 0)
{
rcbNadredeniTicket.DataSource = from t in nadredenTicketList
where t.idFirma == idFirma && t.Zatvoren == false
select new { t.idTicket, t.idNadredeniTicket, OpisTicketa = t.idTicket + " - " + t.Opis };
rcbNadredeniTicket.DataTextField = "OpisTicketa";
rcbNadredeniTicket.DataValueField = "idTicket";
rcbNadredeniTicket.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idNadredeniTicket') %>'";
}
rcbNadredeniTicket.Items.Add(new RadComboBoxItem("Bez nadređenog ticketa", "0"));
rcbNadredeniTicket.DataBind();
RadComboBox rcbPrijavio = (RadComboBox)userControl.FindControl("rcbPrijavio");
rcbPrijavio.DataSource = from k in db.Kontakt
where k.idFirma == idFirma
select new { k.idKontakt, kontaktNaziv = k.Ime + " " + k.Prezime };
rcbPrijavio.Items.Add(new RadComboBoxItem("Bez kontakta", "0"));
rcbPrijavio.DataTextField = "kontaktNaziv";
rcbPrijavio.DataValueField = "idKontakt";
rcbPrijavio.Text = "'<%# DataBinder.Eval(Container, 'DataItem.idKontakt') %>'";
rcbPrijavio.DataBind();
RadComboBox rcbAsset = (RadComboBox)userControl.FindControl("rcbAsset");
var assetList = (from a in db.Asset
where a.idFirma == idFirma
select a).ToList();
if (assetList.Count > 0)
{
var assets = from a in assetList
where a.idFirma == idFirma
select new { a.idAsset, Naziv = a.Naziv + " (" + a.Kontakt.Ime + " " + a.Kontakt.Prezime + ")" };
rcbAsset.DataSource = assets;
rcbAsset.DataTextField = "Naziv";
rcbAsset.DataValueField = "idAsset";
rcbAsset.Text = "'<%# DataBinder.Eval(Container, 'DataItem.Naziv') %>'";
rcbAsset.Items.Add(new RadComboBoxItem("Bez pridruženog asseta", "0"));
rcbAsset.DataBind();
}
if (!e.Item.OwnerTableView.IsItemInserted)
{
int idTicket = Convert.ToInt32(editFormItem.GetDataKeyValue("idTicket"));
ticket = db.Ticket.SingleOrDefault(t => t.idTicket == idTicket);
string tip = ticket.Tip;
rcbTip.Items.FindItemByText(tip).Selected = true;
string status = ticket.Status;
rcbStatus.Items.FindItemByText(status).Selected = true;
string vrstaPrijave = ticket.VrstaPrijave;
rcbVrstaPrijave.Items.FindItemByText(vrstaPrijave).Selected = true;
string prioritet = ticket.Prioritet;
rcbPrioritet.Items.FindItemByText(prioritet).Selected = true;
int kontakt = Convert.ToInt32(ticket.idKontakt);
if (ticket.idKontakt == null)
{
rcbPrijavio.Items.FindItemByValue("0").Selected = true;
}
else
{
rcbPrijavio.Items.FindItemByValue(kontakt.ToString()).Selected = true;
}
int nadredeniTicket = Convert.ToInt32(ticket.idNadredeniTicket);
if (ticket.idNadredeniTicket == null)
{
rcbNadredeniTicket.Items.FindItemByValue("0").Selected = true;
}
else
{
rcbNadredeniTicket.Items.FindItemByValue(nadredeniTicket.ToString()).Selected = true;
}
var ticketAssetCount = from ta in db.TicketAsset
where ta.idTicket == idTicket
select ta;
if (ticketAssetCount.Count() > 0)
{
ticketAsset = db.TicketAsset.SingleOrDefault(ta => ta.idTicket == idTicket);
int asset = Convert.ToInt32(ticketAsset.idAsset);
rcbAsset.Items.FindItemByValue(asset.ToString()).Selected = true;
}
else
{
rcbAsset.Items.FindItemByValue("0").Selected = true;
}
}
else if (e.Item.OwnerTableView.IsItemInserted)
{
var newVals = new System.Collections.Specialized.ListDictionary();
newVals["OpciPrioritet"] = string.Empty;
e.Item.OwnerTableView.InsertItem(newVals);
}
}
}
.aspx:
<telerik:RadGrid ID="gvTicketi" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
onneeddatasource="gvTicketi_NeedDataSource"
onitemdatabound="gvTicketi_ItemDataBound"
oninsertcommand="gvTicketi_InsertCommand"
onupdatecommand="gvTicketi_UpdateCommand">
<MasterTableView DataKeyNames="idTicket" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<CommandItemSettings AddNewRecordText="Dodaj novi ticket" RefreshText="Prikaži sve tickete" />
<Columns>
<telerik:GridBoundColumn UniqueName="idTicket" HeaderText="Ticket" DataField="idTicket">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="idKontakt" HeaderText="Kontakt" DataField="idKontakt">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="idManager" HeaderText="Manager" DataField="idManager">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Opis" HeaderText="Opis" DataField="Opis">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="TicketNumber" HeaderText="Broj ticketa" DataField="TicketNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="DatumPrijave" HeaderText="Datum prijave" DataField="DatumPrijave" DataFormatString="{0:dd.MM.yyyy.}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="VrstaPrijave" HeaderText="Vrsta prijave" DataField="VrstaPrijave">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Tip" HeaderText="Tip" DataField="Tip">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Status" HeaderText="Status" DataField="Status">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Prioritet" HeaderText="Prioritet" DataField="Prioritet">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="OpciPrioritet" HeaderText="Opći prioritet" DataField="OpciPrioritet">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Deadline" HeaderText="Deadline" DataField="DatumDo" DataFormatString="{0:dd.MM.yyyy.}">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn UniqueName="Zatvoren" HeaderText="Zatvoren" DataField="Zatvoren">
</telerik:GridCheckBoxColumn>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
ConfirmDialogType="RadWindow" ConfirmText="Brisanje ticketa!" />
</Columns>
<EditFormSettings UserControlName="UserControls/TicketUserControl.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
I really hope you guys will be able to help me so any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试将以下内容之一添加到 RadTextBox 的数据绑定中:
第一次尝试:
第二次尝试:
第三次尝试:
Try adding one of the following to the databinding of the RadTextBox:
First attempt:
Second attempt:
Third attempt:
好的,我找到了解决方法。您所要做的就是添加 ItemCommand 事件。
Ok, I was able to find a workaround. What you have to do is to add ItemCommand event.
当连接到 GridDropDownColumn 的对象中的字段不可为空时,我在 RadGrids 内部的 GridDropDownColumn 上遇到了同样的问题。
DefaultInsertValue
属性对我来说是关键。对于DataField
中包含整数的下拉列表,我将其设置为 0。如果您的数据类型不像我的那样可以为空,我将使用列中的 ColumnValidationSettings 标记添加验证,以确保它已填写,否则您可能会在提交时收到错误。
I've been having the same issue with
GridDropDownColumn
s inside of RadGrids when the field in the object connected to theGridDropDownColumn
is not nullable. TheDefaultInsertValue
property was the key for me. I set it to 0 for a dropdown with integers in theDataField
.If your data type is not nullable like mine, I would add validation using the
ColumnValidationSettings
tag in the column to make sure it is filled in or you will likely get an error on submission.确保您的 gvTicketi_NeedDataSource 处理程序将网格连接到
List
而不是IEnumerable
。为我解决了这个问题。来源:http://dotfresh.blogspot.com/2010/01/fixing-telerikwebuigridinsertionobject .html
Make sure your gvTicketi_NeedDataSource handler wires your grid up to a
List<T>
notIEnumerable<T>
. Solved the issue for me.Source: http://dotfresh.blogspot.com/2010/01/fixing-telerikwebuigridinsertionobject.html