I'm using ASP.NET AJAX telerik control.
When I use radcombobox autocomplete in Radgrid control, it works.
But when I design it into master/detail radgrid, it failed.
Because the radcombobox autocomplete is in the master grid, when I into detail editmode, code behind ItemDataBound part trigger, cause an error.
So how can I do to trigger the ItemDataBound when Master in edit mode, but not trigger when detail in edit mode? or what condition that can tell which (master or detail) in edit mode?
Thanks in advance.
We can distinguish master and detail grid by using name property. Please try with the below code snippet.
.ASPX
<telerik:RadGrid>
<MasterTableView Name="Parent">
<DetailTables>
<telerik:GridTableView Name="Detail">
<Columns>
.........
.........
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
.........
.........
</Columns>
</MasterTableView>
</telerik:RadGrid>
.CS
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.OwnerTableView.Name == "Parent")
{
//Master table
}
else if (e.Item.OwnerTableView.Name == "Detail")
{
//Detail table
}
}
Related
I am trying to set the SelectedValue of a RadDropDownList in the EditTemplate of my RadGrid. The DataItemBound event appears to be throwing an error on compilation.
ASP.NET
<telerik:GridTemplateColumn DataField="givenAnswer" HeaderText="givenAnswer" UniqueName="givenAnswer">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "givenAnswer") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlGivenAnswer" runat="server" OnItemDataBound="ddlGivenAnswer_DataBound">
<Items>
<telerik:DropDownListItem Text="Yes" Value="Yes" />
<telerik:DropDownListItem Text="No" Value="No" />
</Items>
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
C#
protected void ddlGivenAnswer_DataBound(object sender, GridItemEventArgs e)
{
if ((e.Item.IsInEditMode))
{
GridEditFormItem item = (GridEditFormItem)e.Item;
RadDropDownList ddl = (RadDropDownList)item.FindControl("ddlgivenAnswer");
ddl.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "givenAnswer").ToString();
}
}
Error
CS0123: No overload for 'ddlGivenAnswer_DataBound' matches delegate 'DropDownListItemEventHandler'
This error is being throw on the telerik:RadDropDownList open tag line in ASP.NET. What am I missing here?
Main Edit:
Error CS0123:
First typing CS0123 in Google show me that you were using wrong parameter for your event. Probably a copypast fail. Delete the even in the aspx and ask to intelisense to create a new one. Or copypast this one.
protected void ddlGivenAnswer_ItemDataBound(object sender, Telerik.Web.UI.DropDownListItemEventArgs e)
ItemDataBound:
ItemDataBound occure when a data is bound in a control.
I'am pretty sure that inline declaration are not going to fire this event.
Minor Misconception:
Why would someone change the Value of a selected element dynamically?
It's like changing the value of a vote without changing the vote him self or the name on the vote.
What you want is to check the rigth item.
To check Waldo in the drop down list :
ddlGivenAnswer.FindItemByValue("Waldo").Selected = true;
To check the right Item:
ddlGivenAnswer.FindItemByValue(
DataBinder.Eval(e.Item.DataItem, "givenAnswer").ToString()
).Selected = true;
How do I populate a listbox that is located in the InsertItemTemplate? I need to poplulate this after someone clicks the add new record button and I need to do this in the code behind after they click.
There are few ways of doing it. I prefer Template Edit Form. Here is the sample.
<telerik:RadGrid ... OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
<Columns>
<telerik:GridButtonColumn .../>
</Columns>
<EditFormSettings ColumnNumber="1" EditFormType="Template">
<FormTemplate>
<asp:ListBox .../>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Updated:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
var item = e.Item as GridEditFormItem;
var listBox1 = item.FindControl("ListBox1") as ListBox;
// Fills listbox with data
listBox1.DataSource = listboxdata;
listBox1.DataBind();
}
}
I have a peculiar problem and I am not sure if anyone had come across this problem earlier. however the issue goes like this..
I have a grid with combination of TemplateColumns and BoundColumns and when I filter the grid using the filters under template columns I can see the results in UI (grid) but when I do the same in BoundColumns I do not see any results.. !!!
Funny thing is I can see the output from the query and its returns the correct number of results from DB. and its also assigned to the GridDataSource in the NeedDataSource event. however I cannot find the GridDataItem in the ItemDataBoundItem, I can fetch only headeritem, filteritem and footeritem.
It shows "No records to display" even when there are lot of records assigned to the DataSource.
Here I am attaching the screenshot, where you can see that the records count is displayed but not the records.. !!
Any help is highly appreciated.
here is the code sample
<ps:MassApprovalAjaxPanel runat="server" ID="m_UIRadAjaxPanel" LoadingPanelID="m_UIAsynBindLoadPanelInMasterPage">
<ps:MassApprovalRadGrid
runat="server"
ID="m_UIListingGrid"
SkinID="Grid_MassApproval"
OnNeedDataSource="ListingGrid_NeedDataSource"
OnItemDataBound="ListingGrid_ItemDataBound"
AllowFilteringByColumn="true"
EnableViewState="true">
<MasterTableView
DataKeyNames="CardID, WeekEnding, ClientPONumber"
ShowFooter="true">
<Columns>
<ps:NumericTextBoxTemplateColumn
UniqueName="CardID"
Width="70"
RelativeWidthRatio="90">
<ItemTemplate>
<asp:Label
runat="server"
Text='<%# string.Format("{0}/{1}", Eval(Constants.CARD_ID), Eval(Constants.VERSION)) %>' />
</ItemTemplate>
</ps:NumericTextBoxTemplateColumn>
<ps:TextBoxBoundColumn
UniqueName="ClientPONumber"
DataField="ClientPONumber"
Width="60"
RelativeWidthRatio="80" />
<telerik:GridClientSelectColumn UniqueName="SelectAll" HeaderText="All" />
</Columns>
</MasterTableView>
</ps:MassApprovalRadGrid>
</ps:MassApprovalAjaxPanel>
protected void ListingGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
m_UIListingGrid.DataSource = RadGridUtilUI.MassApprovalResultsGet();
}
protected void ListingGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem gridDataItem = e.Item as GridDataItem;
if (gridDataItem != null)
{
AddClientScripts(gridDataItem);
}
}
Thanks,
Preetham.
I found fix for this issue, it was quite simple and straight forward but we did not notice it.
protected void ListingGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
m_UIListingGrid.MasterTableView.FilterExpression = string.Empty;
m_UIListingGrid.DataSource = RadGridUtilUI.MassApprovalResultsGet();
}
Telerik has two types of filtering which is inbuilt filtering and user defined filtering that we do it through our SP's and Code. so we always have to set the filter value to null before doing our custom filtering.
Mark this as answer.
Thanks,
Preetham.
Can anyone give me any hint on how I can open a new window by selecting a record from a gridview?
Im using response.redirect, and passing a value at present which opens the page fine but Id rather have a popup for this
thanks
You need to bind click event with the row of the grid view control
following code is just demo for you
following javascript open up the pop up window where you need to pass the url you want
<script>
function popWin(url){
window.open(url, '', '');");
}
</script>
follwing is samle code that attch the script with the gridview row to open up popup
code behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow )
{
string url = "www.google.com";
e.Row.Attributes.Add("onclick","popWin('" + url + "')");
}
}
I had the same issue with response.redirect so went with a asp:HyperLink button instead. I loaded the URL by Binding it through the SQL Database. Here is the code:
<asp:TemplateField HeaderText="Google Map">
<ItemTemplate>
<asp:HyperLink runat="server" ID="hlGMap" Target="_blank" Text="Map" ImageUrl="~/gfx/google.png" NavigateUrl='<%# Bind("GoogleMapsURL") %>' />
</ItemTemplate>
</asp:TemplateField>
Hope it helps.
I have a repeater that contains a Telerik RadComboBox:
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
<telerik:RadComboBox ID="rcb" runat="server" EnableLoadOnDemand="true"
AllowCustomText="true" ItemRequestTimeout="1000"
NumberOfItems="10" MarkFirstMatch="false">
</telerik:RadComboBox>
</ItemTemplate>
</asp:Repeater>
In the ItemDataBound event of the Repeater, I am wiring up the ItemsRequested event like this:
private void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e) {
RadComboBox rcb = (RadComboBox)e.Item.FindControl("rcb");
rcb.ItemsRequested += rcb_ItemsRequested;
}
private void rcb_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) {
// Database call to load items occurs here.
// As configured, this method is never called.
}
Currently, the server-side rcb_ItemsRequested method is never called. I suspect that wiring the ItemsRequested event in the ItemDataBound is problematic, but the problem may lie elsewhere.
Any ideas on how to use the Telerik RadComboBox within a repeater properly?
Have you tried putting the event handler wiring in the markup rather than adding it dynamically?
Also - you are probably aware, but just in case - ItemsRequested is an event that only fires under certain conditions. To quote the docs:
The ItemsRequested event occurs when the EnabledLoadOnDemand property is True and the user types text into the input field or clicks on the drop-down toggle image when the list is empty. - Reference
Does your scenario match the above?
EDIT:
I've tested some code. The following works (The ItemsRequested Event fires for the all ComboBoxes and adds the three test items to the dropdown on the fly..):
Markup:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">
<ItemTemplate>
<br />
<telerik:RadComboBox ID="rcb" runat="server" EnableLoadOnDemand="true" AllowCustomText="true"
ItemRequestTimeout="1000" NumberOfItems="10" MarkFirstMatch="false" />
</ItemTemplate>
</asp:Repeater>
</form>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
List<string> data = new List<string>();
data.Add("Item 1");
data.Add("Item 2");
//add some items to the repeater to force it to bind and repeat..
rpt.DataSource = data;
rpt.DataBind();
}
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//wire the event
RadComboBox rcb = (RadComboBox)e.Item.FindControl("rcb");
rcb.ItemsRequested += rcb_ItemsRequested;
}
protected void rcb_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
//add the items when requested.
(sender as RadComboBox).Items.Add(new RadComboBoxItem("Item1", "1"));
(sender as RadComboBox).Items.Add(new RadComboBoxItem("Item2", "2"));
(sender as RadComboBox).Items.Add(new RadComboBoxItem("Item3", "3"));
}