protected
void Grid_ItemCreated(object sender, GridItemEventArgs e) {
if (!IsPostBack && e.Item is GridDataItem) {
e.Item.Edit =
true;
}
}
But when ItemDataBound even is fired IsInEditMode property is still set to false. But Edit property is correctly set to true. In the RadGrid documentation says "We suggest using IsInEditMode instead of Edit to check whether an Item is in edit more or not.". But the IsInEditMode property is set to false. Why is IsInEditMode property not set to true? I added my item data bound event handler below.
protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {
if
(e.Item is GridEditableItem && e.Item.IsInEditMode) {
//--------------------------------------never getting to this block
DropDownList statusDropDown = editedItem.FindControl("StatusDropDown") as DropDownList;
//do something with statusDropDown
}
}
I tried changing my event handle to use Edit property instead, then the code is not finding control in the EditItemTemplate StatusDropDown DropDownList.
Here is my modified code and grid decleration:
protected void Grid_ItemDataBound(object sender, GridItemEventArgs e) {
if
(e.Item is GridEditableItem && e.Item.Edit) {
//------------------------------------------------I am geting null for statusDropDown
DropDownList statusDropDown= editedItem.FindControl("StatusDropDown") as DropDownList;
//do something with statusDropDown
}
}
<telerik:RadGrid ID="Grid" runat="server" GridLines="None" AutoGenerateColumns="false"
OnItemDataBound="Grid_ItemDataBound" OnNeedDataSource="Grid_NeedDataSource"
OnItemCreated="Grid_ItemCreated" AllowMultiRowEdit="true">
<MasterTableView DataKeyNames="ClassId" EditMode="InPlace">
<Columns>
<telerik:GridBoundColumn UniqueName="ClassName" HeaderText="Class Name" DataField="ClassId"
ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Site" DataField="SiteId" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="Status" HeaderText="Status">
<ItemTemplate>
<asp:Label ID="statusLabel" runat="server">
<%# DataBinder.Eval(Container.DataItem, "StatusId")%>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="StatusDropDown" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
I am trying to avoid using prerenderer becasue of rebind call.
Anyone has any idea what I am missing. Please let me know if you see a better way to do this. I appreciate any help.
Thanks,
Ana
I'm writing to ask how best to maintain the Empty Message value in a RadComboBox - after the selection of a RadComboBoxItem;
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
Skin
=
"Black"
AutoPostBack
=
"True"
onselectedindexchanged
=
"RadComboBox1_SelectedIndexChanged"
Font-Names
=
"Microsoft Sans Serif"
Width
=
"160px"
EmptyMessage
=
"Maines Paper"
MarkFirstMatch
=
"True"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Sign out"
Value
=
"Sign out"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Change Password"
Value
=
"Change Password"
/>
</
Items
>
</
telerik:RadComboBox
>
<
telerik:RadGrid
ID
=
"RadGrid2"
GridLines
=
"None"
AutoGenerateColumns
=
"false"
PageSize
=
"7"
AllowPaging
=
"true"
AllowSorting
=
"true"
runat
=
"server"
OnItemDataBound
=
"OnItemDataBoundHandler"
DataSourceID
=
"ProductsDataSource"
AllowAutomaticUpdates
=
"true"
AllowAutomaticInserts
=
"True"
ShowStatusBar
=
"true"
Skin
=
"Office2010Blue"
>
<
MasterTableView
ShowFooter
=
"false"
DataKeyNames
=
"inventoryid"
EditMode
=
"InPlace"
CommandItemDisplay
=
"TopAndBottom"
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"conditioncode"
HeaderText="<%$ Resources:locStrings, GV_COL_PO_ConditionCode %>" SortExpression="conditioncode" ItemStyle-Width="150px">
<
FooterTemplate
> Template footer</
FooterTemplate
>
<
FooterStyle
VerticalAlign
=
"Middle"
HorizontalAlign
=
"Center"
/>
<
ItemTemplate
>
<%#DataBinder.Eval(Container.DataItem, "conditioncode")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBox1"
EnableLoadOnDemand
=
"True"
DataTextField
=
"code"
DataValueField
=
"conditionid"
AutoPostBack
=
"true"
HighlightTemplatedItems
=
"true"
Height
=
"140px"
Width
=
"150px"
DropDownWidth
=
"200px"
OnItemsRequested
=
"RadComboBox1_ItemsRequested"
OnSelectedIndexChanged
=
"OnSelectedIndexChangedHandler"
>
<
HeaderTemplate
>
<
ul
>
<
li
class
=
"col1"
>Code</
li
>
<
li
class
=
"col2"
>Condition</
li
>
</
ul
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
ul
>
<
li
class
=
"col1"
>
<%# DataBinder.Eval(Container,"Text")%>
</
li
>
<
li
class
=
"col2"
>
<%# DataBinder.Eval(Container,"Attributes['code']")%></
li
>
</
ul
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
FooterText
=
"EditCommand footer"
UniqueName
=
"EditCommandColumn"
HeaderText
=
"Edit"
UpdateText
=
"Update"
HeaderStyle-Width
=
"100px"
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"ProductsDataSource"
runat
=
"server"
ConnectionString
=
"Data Source=VSSCLOUDAPP1;Initial Catalog=iqrtest_20113108;User ID=sa; Password=admin!23"
SelectCommand="SELECT ptid, inventoryid, unitcost, conditioncode, status, receivestatus, mfgr
FROM inventory WHERE
ptid
=
501
">
</
asp:SqlDataSource
>
C#:
protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
if (!(e.Item is IGridInsertItem))
{
RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
RadComboBoxItem selectedItem = new RadComboBoxItem();
selectedItem.Value = ((DataRowView)e.Item.DataItem)["conditionid"].ToString();
selectedItem.Text = ((DataRowView)e.Item.DataItem)["code"].ToString();
selectedItem.Attributes.Add("condition", ((DataRowView)e.Item.DataItem)["condition"].ToString());
combo.Items.Add(selectedItem);
selectedItem.DataBind();
Session["conditionid"] = selectedItem.Value;
}
}
}
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
DataTable dt = new DataTable();
dt = IQR.Generic.cGeneric.GetData(cStoredProcedureConstants.SP_POItem_GetConditionCodes, true);
RadComboBox rcbConditionCode = (RadComboBox)sender; // Clear the default Item that has been re-created from ViewState at this point. comboBox.Items.Clear();
foreach (DataRow row in dt.Rows)
{
RadComboBoxItem item = new RadComboBoxItem();
item.Value = row["conditionid"].ToString();
item.Text = row["code"].ToString();
item.Attributes.Add("condition", row["condition"].ToString());
rcbConditionCode.Items.Add(item);
item.DataBind();
}
}
protected void OnSelectedIndexChangedHandler(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
Session["conditionid"] = e.Value;
}