Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
168 views

I have a need to programmatically create a RadGrid based on the number of elements from another table.  So I have the following:

foreach (DataRow customerRow in dtDistinctMonitors.Rows)
            {
                //Get Data
                DataRow[] rowData = dtMonitors.Select("tenantID = '" + tenantID + "'");

                //Add Label
                Label lblName = new Label();
                lblName.Text = "Channel: xxxx";
                lblName.Font.Size = FontUnit.Large;
                PlaceHolder1.Controls.Add(lblName);

                //Add RadGrid
                RadGrid RadGrid1 = new RadGrid();
                RadGrid1.ID = customerRow["channelID"].ToString();

                //Add RadGrid to the Controls collection of the placeholder
                PlaceHolder1.Controls.Add(RadGrid1);

                RadGrid1.DataSource = rowData;
                RadGrid1.MasterTableView.DataKeyNames = new string[] { "monitorID" };
                RadGrid1.AllowPaging = false;
                RadGrid1.MasterTableView.AutoGenerateColumns = false;
                RadGrid1.Skin = "Silk";
                RadGrid1.RenderMode = RenderMode.Lightweight;
                RadGrid1.Width = Unit.Percentage(100);
                GridBoundColumn boundColumn;
                boundColumn = new GridBoundColumn();
                RadGrid1.MasterTableView.Columns.Add(boundColumn);
                boundColumn.DataField = "monitorName";
                boundColumn.HeaderText = "Monitor Name";
                GridButtonColumn buttonColumn;
                buttonColumn = new GridButtonColumn();
                buttonColumn.Text = "Delete";
                buttonColumn.ButtonType = GridButtonColumnType.LinkButton;
                buttonColumn.HeaderStyle.Width = Unit.Pixel(100);
                buttonColumn.CommandArgument = "monitorID";
                buttonColumn.CommandName = "lnkDelete_Command";
                RadGrid1.MasterTableView.Columns.Add(buttonColumn);
            }

And below I have lnkDelete_Command as:

public void lnkDelete_Command(object sender, CommandEventArgs e)
    {
        using (SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["stringvalue"].ConnectionString))
        {
            string ID = e.CommandArgument.ToString();

            //DELETE FROM WHERE ID = ID
        }
    }

 

Yet, when I click on the LinkButton created it doesn't fire.  It doesn't really do anything at all but creates a second instance of the button.  Am I missing something simple here?

Marin Bratanov
Telerik team
 answered on 26 Nov 2018
4 answers
133 views
Hi All ,

I am using radscheduler.

In All Day section of radscheduler the appointment are show as one below the other.
So its height get increase.

I want to show the appointment one beside the other(i.e. in one row) like it shows in time slot
For ex.
I)For 7.00-7.30 AM time slot
If there are more than one appointment then it show one beside the other.

Muhammad Motawe
Top achievements
Rank 1
 answered on 26 Nov 2018
1 answer
272 views

I have the radgrid and commandItemTemplate as follows:

<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="calendarTableView" OnItemCommand="ItemCommand" >
    <MasterTableView AutoGenerateColumns="false" TableLayout="Fixed" CommandItemDisplay="Top">
        <CommandItemTemplate>
            <asp:TextBox ID="txtFilter" runat="server"></asp:TextBox>
            <asp:Button ID="btnFilter" runat="server" Text="Apply Filter" CommandName="FilterAll" />
            <asp:Button ID="btnClear" runat="server" Text="Clear Filter" CommandName="ClearFilter" />
        </CommandItemTemplate>
    </MasterTableView>
</telerik:RadGrid>

and in the vb file I have

Protected Sub ItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs)
    Dim filterExpression As String = String.Empty
    If e.CommandName = "FilterAll" Then
        Dim cmdItem As GridCommandItem = TryCast(e.Item, GridCommandItem)
        Dim txtFilter = TryCast(cmdItem.FindControl("txtFilter"), TextBox)
        For Each col As GridColumn In calendarTableView.MasterTableView.Columns
            For Each dataItem As GridDataItem In calendarTableView.Items
                If dataItem(col.UniqueName).Text.Contains(txtFilter.Text) Then
                    filterExpression = "([" + col.UniqueName + "] = '%" + txtFilter.Text + "%')"
                    calendarTableView.MasterTableView.FilterExpression = filterExpression
                End If
            Next
        Next
        calendarTableView.MasterTableView.Rebind()
    ElseIf e.CommandName = "ClearFilter" Then
        Dim cmdItem As GridCommandItem = TryCast(e.Item, GridCommandItem)
        Dim txtFilter As TextBox = TryCast(cmdItem.FindControl("txtFilter"), TextBox)
        txtFilter.Text = String.Empty
        calendarTableView.MasterTableView.FilterExpression = String.Empty
    End If
End Sub

 

but I am running into 2 problems.  1, it's not getting the text from the txtFilter textbox correctly and 2, the line " calendarTableView.MasterTableView.Rebind() " comes up with an exception saying it expected an expression.

Marin Bratanov
Telerik team
 answered on 23 Nov 2018
4 answers
221 views
Hi everyone,

On the server, I can do this:

RadListBox1.EmptyMessage = "No items available";

How can I then alter this text later using the client-side API?  The equivalent function or property does not seem to exist.

My project makes extensive use of AJAX and client-side updating, which can leave some of my list-boxes in an "indeterminate state" as they can only be adequately updated on the server (through data-binding).  Therefore I want to be able to clear these list-boxes on the client and display a temporary message that says "Click this button to refresh the list", where the button will then trigger a post-back and cause the current data to be bound to the list-box on the server.  Does that make sense?

Ed Graham
Peter Milchev
Telerik team
 answered on 23 Nov 2018
0 answers
111 views

I have two rad-wizards and a text box in each wizard, i want to set the same value(from db) for two text-boxes on clicking of button. I know how to set for one at a time. Can someone help me to achieve this.

Markup:

 

<telerik:RadWizardStep Title="Step Properties" runat="server">
        <table style="width:100%">
            <tr>
                <td style="width: 35%;" class="td_label" valign="top">
                    <telerik:RadLabel runat="server" RenderMode="Lightweight" ID="RadLabel1" Text="Sln Form:" CssClass="LabelStyle">
                    </telerik:RadLabel>
                </td>
                <td class="noWrap">
                    <telerik:RadTextBox runat="server" RenderMode="Lightweight" ID="slnForm" Enabled="false" CssClass="TextBoxMandatoryStyle">
                    </telerik:RadTextBox>
                </td>
            </tr>
        </table>
</telerik:RadWizardStep>
 
<telerik:RadWizardStep Title="Form" runat="server" ID="rformWizard">
        <table style="width: 100%">
            <tr>
                <td style="width: 35%;" class="td_label" valign="top">
                    <telerik:RadLabel runat="server" RenderMode="Lightweight" ID="SlnLabel" Text="SLN Form:" CssClass="LabelStyle">
                    </telerik:RadLabel>
                </td>
                <td class="noWrap">
                    <telerik:RadTextBox RenderMode="Lightweight" ID="slntxt" Enabled="false" runat="server" CssClass="TextBoxMandatoryStyle">
                    </telerik:RadTextBox>
                </td>
            </tr>
<telerik:RadWizardStep>
Saifulla
Top achievements
Rank 1
 asked on 22 Nov 2018
3 answers
481 views

Hi, I need to extract the new values from the GridDateTimeColumn to validate that one date is not greater than or less than another as needed. Do this but only extract the previous values in the edited items.

<MasterTableView DataSourceID="sdsControlGranel" AutoGenerateColumns="False" CommandItemDisplay="Top" EditMode="Batch">
            <CommandItemSettings SaveChangesText="Guardar cambios" CancelChangesText="Cancelar cambios" ShowExportToExcelButton="True" ShowAddNewRecordButton="false"></CommandItemSettings>
            <BatchEditingSettings EditType="Row" />
            <Columns>
                <telerik:GridDateTimeColumn DataField="FcAsignacion" HeaderText="Fecha Asignación" SortExpression="FcAsignacion" UniqueName="FcAsignacion" DataType="System.DateTime" PickerType="DateTimePicker" FilterControlAltText="Filter FcAsignacion column" CurrentFilterFunction="Contains">
</telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="FcInicioOperacion" HeaderText="Fecha Inicio" SortExpression="FcInicioOperacion" UniqueName="FcInicioOperacion" DataType="System.DateTime" PickerType="DateTimePicker" FilterControlAltText="Filter FcInicioOperacion column" CurrentFilterFunction="Contains">
</telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="FcFinalOperacion" HeaderText="Fecha Final" SortExpression="FcFinalOperacion" UniqueName="FcFinalOperacion" DataType="System.DateTime" PickerType="DateTimePicker" FilterControlAltText="Filter FcFinalOperacion column" CurrentFilterFunction="Contains">
</telerik:GridDateTimeColumn>
            </Columns>
        </MasterTableView>
 

 

protected void rgControlGranel_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            Hashtable newValues = new Hashtable();
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
            DateTime fcAsignacion = Convert.ToDateTime(newValues["FcAsignacion"].ToString());
            DateTime fcInicio = Convert.ToDateTime(newValues["FcInicioOperacion"].ToString());
 
            if (DateTime.Compare(fcAsignacion, fcInicio) > 0)
            {
                e.Canceled = true;
                this.TextoMensaje("La fecha de asignación no puede ser mayor a la de inicio", 3);
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "MostrarMensaje();", true);
            }
        }

 

 

 

 

Attila Antal
Telerik team
 answered on 22 Nov 2018
2 answers
268 views

Thought this should be easy, but I think I am missing something very fundamental here.

 Requirement: I have added RadScheduler to the content page and want to set the height to 100% of DIV - DIV's height is fluid - fills entire space between content header and content footer.

 Issues

  1. If I set Overflow='Expanded' it expands BEYOND the page but with no scroll - so I can only see between 00:00 to 15:00! Rest is hidden
  2. If I set overflow ='Auto' - same results as above
  3. If I set Overflow='Scroll' and set the height in % - The height setting in % does seem to do any good and height is more than the containing div
  4. If I set overflow='Scroll' and set height in px - it is not fluid as I wouldn't know the px height in all over config or when window is resized
  5. If I set Overflow='Expanded' and let the overflow of container div to auto then the Radscheduler headers (date and times of event) is no longer fixed 
  6. If I set the overflow = 'Scroll' and set the height using jQUERY when page load and window resizes; all is fine until I move to the next week/month then height is set to 400px (default)

What am I missing here?

 Thanks in advance     

 

Siva
Top achievements
Rank 1
 answered on 22 Nov 2018
9 answers
932 views
I have a GridDateTimeColumn on my radgrid that is not filtering correctly. When I change the date to be less than a certain date it is not filtering the data correctly. I am assuming it has something to do with the date not being formatted as MM/dd/yyyy and having a time stamp. Here is my code ...

Any help here?

Trevor

<
telerik:GridDateTimeColumn HeaderText="Creation Date" DataFormatString="{0:MM/dd/yyyy hh:mm:ss}" SortExpression="Created" ItemStyle-Wrap="false" UniqueName="Created" DataField="whenCreated" FilterListOptions="VaryByDataType" FilterImageUrl="~/images/filter_icon.gif" FilterControlWidth="100px" />
venkat
Top achievements
Rank 1
 answered on 22 Nov 2018
9 answers
1.4K+ views

I'm trying to get RadGrid to conditionally hide or disable a field when it is in edit mode based on the value of another field.

I have been able to get this to work when the grid displays the list of items, but once the grid enters edit mode, the columns display ...

I am using OnItemDataBound to successfully conditionally display during the initial load, but setting the items when the user clicks a row to get it into batch mode is not working.

I'm also trying to set the tab order when I go into edit mode, for some reason, the grid throws the cursor to the 2nd column ...

Note: PValue and CValue and in GridTemplateColumns, as is CardStatus.


public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
foreach (GridDataItem item in RadGrid1.Items)
       {
          string BoundColumnValue = item["CardStatus"].Text; // accessing    GridBoundColumn value using ColumnUniqueName
            string BoundColumnValue2 = item["CValue"].Text;
            TextBox txtbx = (TextBox)item.FindControl("CardStatus");
            Label numlb = (Label)item.FindControl("CardValue");
 
            if (txtbx.Text.Equals("True"))
            {
                txtbx.ForeColor = Color.Red;
 
                numlb.Enabled = false;
                numlb.BackColor = Color.Yellow;
                numlb.ForeColor = Color.Red;
               //Just testing to see if it would evaluate
            }
            else
            {
                txtbx.ForeColor = Color.Beige;
            }
            //string TemplateColumnValue = lb.Text;// accessing Label Text.
        }
 
        foreach (GridEditableItem item in RadGrid1.EditItems)
        {
            string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
            string BoundColumnValue2 = item["CValue"].Text;
            TextBox txtbx = (TextBox)item.FindControl("CardStatus");
            if (txtbx.Text.Equals("True"))
            {
                txtbx.ForeColor = Color.Red;
 
                //numTxt.BackColor = Color.Yellow;
                //numTxt.ForeColor = Color.Red;
            }
            else
            {
                txtbx.ForeColor = Color.Beige;
            }
}
}

I just need to be able to selectively prevent data entry in a column

The ASPX source is below:


          <telerik:GridTemplateColumn ColumnEditorID="CValue" DataField="CValue" HeaderText="Card" UniqueName="CValue" ItemStyle-Width="75px" HeaderStyle-Width="75px">
 
                                    <EditItemTemplate>
 
                                        <telerik:RadNumericTextBox ID="CValue" Width="50px" AllowOutOfRangeAutoCorrect="false"  runat="server" MaxLength="1" MaxValue="1" NumberFormat-DecimalDigits="0" Text='<%# Bind("CValue") %>'></telerik:RadNumericTextBox>
                                        <asp:RequiredFieldValidator runat="server" ControlToValidate="CValue" ErrorMessage="<br />Required (0-1 Only)!" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="CValue" Width="50px" runat="server" Text='<%# Bind("CValue") %>'></asp:Label>
                                    </ItemTemplate>
 
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="DateEdited" ReadOnly="true" Visible="false" DataType="System.DateTime" FilterControlAltText="Filter DateEdited column" HeaderText="DateEdited" SortExpression="DateEdited" UniqueName="DateEdited">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn UniqueName="CardStatus" DataField="CardStatus" ItemStyle-Width="50px" HeaderStyle-Width="50px">
                                <ItemTemplate>
                              <asp:TextBox ID="CardStatus" Width="10px"  runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>          
                                </ItemTemplate>
                                    <EditItemTemplate>
      <asp:TextBox ID="CardStatus" Width="10px"  runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>          
 
                                    </EditItemTemplate>
 
                            </telerik:GridTemplateColumn>
 
                            </Columns>
 
                        </MasterTableView>
 
                        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
 
                        <FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>

Any help / workarounds would be appreciated ... again, "just" need to prevent editing in the CValue column when the CardStatus value is true (bit field) ... using batch mode (using another solution isn't an option now).

Also, the issue with the tab order being messed up is particularly frustrating ... any hints on that one?

Thanks

Larry


(sorry , this is cross-posted elsewhere, but am a bit desperate right now).
Peter Milchev
Telerik team
 answered on 22 Nov 2018
2 answers
317 views

Is there any way to delete a record server side from a control outside of the RadGrid and have the grid update when the postback returns?

I have a LinkButton that handles deleting a record from the datasource and then calls the RadGrid Rebind method.

This triggers the NeedDataSource() method to fire and subsequently the RadGrid PreRender.  The problem is that when the page finishes the postback, the deleted row is still visible in the grid.  Any other interaction with the grid such as selecting a row or sorting, calls NeedDataSource again and the deleted row is gone.

I've verified that the data that comes back to NeedDataSource right after delete does not contain the row that was deleted.  

There is a similar "Add" functionality that works fine.  Meaning the row is added, data updated and Rebind called and grid shows the new row.  I presume this is because the add calls a RadWindow that is still within the RadPanel that contains the RadGrid whereas the Delete button is outside of the Panel.

 

Here is the psuedo code of what I'm doing.

Private Sub ibtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ibtnDelete.Click
    DeleteRecord()
End Sub
 
Private Sub DeleteRecord()
   DeleteLogicHere()
  UpdateDataSourceHere()
  RadGrid1.Rebind()
End Sub
 
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    RadGrid1.DataSource = FetchDataSourceHere()
End Sub

 

Here is a mockup of the aspx side.

<asp:LinkButton ID="ibtnDelete" CssClass="icon delete" TabIndex="10" runat="server" ToolTip="Delete Current Record"
ClientClick="return confirm('Are you sure you want to delete this record? If yes, click OK.');"></asp:LinkButton>
 
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" CssClass="controlsWrapper">
    <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"
        AllowPaging="True" AllowSorting="true" AutoGenerateColumns="false"
        OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"
        OnPreRender="RadGrid1_PreRender"
        OnSortCommand="RadGrid1_SortCommand"
        OnPageIndexChanged="RadGrid1_PageIndexChanged"
        OnPageSizeChanged="RadGrid1_PageSizeChanged">  
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

 

I have also tried adding ibtnDelete to the RadAjaxManager with the RadGrid, but that did not resolve anything.

Eyup
Telerik team
 answered on 22 Nov 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?