Telerik Forums
UI for ASP.NET AJAX Forum
4 answers
168 views
Hi,
I have the following challenge and I do not know how to solve this.
When the user enter the date in a dateTime column "Date" in edit mode, I need the week number to be automatically inserted in a bound column and saved to the db.
The week number is calculated in a method from code behind:

private static int WeekOfYear(DateTime date)
    {
        var day = (int)CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(date);
        return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date.AddDays(4 - (day == 0 ? 7 : day)), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
    }

This is my actual grid:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Culture="it-IT" DataSourceID="SqlDataSource1" PageSize="20" CellSpacing="-1" GridLines="Both">
                        <ExportSettings>
                            <Pdf PageHeight="297mm" PageWidth="" PaperSize="A4">
                            </Pdf>
                        </ExportSettings>
                        <ClientSettings>
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </ClientSettings>
                        <MasterTableView CommandItemDisplay="Top" DataKeyNames="Id" DataSourceID="SqlDataSource1" Caption="Working Hours" >
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                                    <HeaderStyle Width="25px" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                    <HeaderStyle HorizontalAlign="Left" Width="35px" />
                                </telerik:GridBoundColumn>
                                <telerik:GridDateTimeColumn DataField="Date" DataFormatString="{0:dd/MM/yyyy}" FilterControlAltText="Filter Date column" HeaderText="Date" SortExpression="Date" UniqueName="Date">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                    <HeaderStyle HorizontalAlign="Center" Width="85px" />
                                </telerik:GridDateTimeColumn>
 
                                <telerik:GridTemplateColumn DataField="Pnum" FilterControlAltText="Filter Pnum column" HeaderText="P Number" SortExpression="Pnum" UniqueName="Pnum">
                                    <EditItemTemplate>
                                        <telerik:RadComboBox ID="PnumRadComboBox" runat="server" DataSourceID="SqlDataSource2" DataTextField="Pnum" DataValueField="Pnum" SelectedValue='<%# Bind("Pnum") %>'>
                                        </telerik:RadComboBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="PnumLabel" runat="server" Text='<%# Eval("Pnum") %>'></asp:Label>
                                    </ItemTemplate>
                                    <HeaderStyle HorizontalAlign="Center" Width="65px" />
                                </telerik:GridTemplateColumn>
 
                                <telerik:GridDateTimeColumn DataField="WorkedTime" FilterControlAltText="Filter column column" PickerType="TimePicker" DataFormatString="{0:hh\:mm}" HeaderText="Worked Time" SortExpression="WorkedTime" UniqueName="column">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                    <HeaderStyle HorizontalAlign="Center" Width="65px" />
                                </telerik:GridDateTimeColumn>
 
                                <telerik:GridBoundColumn DataField="Note" FilterControlAltText="Filter Note column" HeaderText="Note" SortExpression="Note" UniqueName="Note">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                    <HeaderStyle HorizontalAlign="Center" />
                                </telerik:GridBoundColumn>
                                <telerik:GridClientDeleteColumn ButtonType="ImageButton" FilterControlAltText="Filter column1 column" UniqueName="column1">
                                    <HeaderStyle Width="25px" />
                                </telerik:GridClientDeleteColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
I would appreciate your help to solve this.
Thanks you,
Felice
Konstantin Dikov
Telerik team
 answered on 16 Apr 2014
2 answers
189 views
I am getting the following error on a form grid:

Exception type: IndexOutOfRangeException
Exception message: Cannot find table 0.
   at System.Data.DataTableCollection.get_Item(Int32 index)
   at storagePortal.shipout.RadGrid1_NeedDataSource(Object source, GridNeedDataSourceEventArgs e)
   at Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e)
   at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
   at Telerik.Web.UI.RadGrid.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The web page was working fine yesterday.  Nothing changed that I know of, but this error is appearing today. The data source is provided by a stored procedure that I ran separately - it works fine.  Anyone have any ideas? 


Jayesh Goyani
Top achievements
Rank 2
 answered on 16 Apr 2014
1 answer
65 views
I have 3 dropDownList in my grid, all bind to Sql tables with SqlDatasource. The first one "Pnum" acts like I need, i.e. when a value is selected it stays there even when I re-open the record for modification. The other two "minutes" and "hours" behave in a different way, I mean every time I open the record for modification, the selected value is set to the first one in the db or nothing.

This is the good one:

<EditFormSettings EditFormType="Template">
<FormTemplate>
<table class="table">
.........
<telerik:RadDropDownList ID="RadDropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Pnum" DataValueField="Pnum"
SelectedValue='<%#Bind("Pnum") %>' Skin="Outlook" AutoPostBack="true">
</telerik:RadDropDownList>


These two give me the problem:

<telerik:RadDropDownList ID="RadDropDownList2" runat="server" DataSourceID="SqlDataSource3"
DataTextField="minutes" DataValueField="minutes" SelectedValue='<%#Bind("minutes") %>'
Skin="Outlook" AutoPostBack="true">
</telerik:RadDropDownList>
 
<telerik:RadDropDownList ID="RadDropDownList3" runat="server" DataSourceID="SqlDataSource4"
DataTextField="hours" AutoPostBack="false" DataValueField="hours"
SelectedValue='<%#Bind("hours") %>' Skin="Outlook">
</telerik:RadDropDownList>
.......
</table>
 </FormTemplate>
</EditFormSettings>


I do not see any difference that may cause such different behavior. Any hint on how to solve this problem? I mean, avoid that the value is changed when opening the record for modification.
Princy
Top achievements
Rank 2
 answered on 16 Apr 2014
20 answers
1.0K+ views
Hi all,

http://www.telerik.com/help/aspnet/grid/grddefaulteditmodeforgriditemsoninitialload.html


foreach(GridItem item in RadGrid1.MasterTableView.Items)
 {
  
if (item is GridEditableItem)
  {
   GridEditableItem editableItem= item
as GridDataItem;
   editableItem.Edit = true;
  }
 }
 RadGrid1.Rebind();


i am using the method in the above link to make my Radgrid editable on click of a button.
But.. this is not working... in fact when i click on another button t change it back to normal mode...it now appears in edit mode.!!!

can anyone help me?
Thanks in advance
John
Shinu
Top achievements
Rank 2
 answered on 16 Apr 2014
1 answer
108 views
Hi,
I have these two dropdownlists in a Edit Form Template where I tried to set the number of items to show and/or the height but is not producing any effect. please look at the pictures attached.

<EditFormSettings EditFormType="Template">
   <FormTemplate>
      <table class="table">
 
    <telerik:RadDropDownList ID="RadDropDownList2" ItemCountPerRequest="4"
     DefaultMessage="Please select a value" runat="server" DataSourceID="SqlDataSource3"
     DataTextField="minutes" DataValueField="minutes" SelectedValue='<%#Bind("minutes") %>' Skin="Outlook">
        </telerik:RadDropDownList>
 
    <telerik:RadDropDownList ID="RadDropDownList3" runat="server" ItemCountPerRequest="12"
     DataSourceID="SqlDataSource4" DataTextField="hours" DefaultMessage="Please select a value"
     DataValueField="hours" SelectedValue='<%#Bind("hours") %>' Skin="Outlook">
        </telerik:RadDropDownList>
 
      </table>
   </FormTemplate>
</EditFormSettings>
What I would like to achieve is the following:
For the dropdownlist "Minutes" shows only the 4 items
For the dropdownlist "hours" show the first 12" values and then the others only on demand.
How can I fix these dropdownlists to achieve the above scenario?
Thanks for the support,
Felice
Shinu
Top achievements
Rank 2
 answered on 16 Apr 2014
1 answer
238 views
Advanced data binding with NeedDataSource event works perfectly for me when I need paging, sorting, grouping and filtering.
Below is the code snippet from your documentation:

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address FROM Customers", conn);
 
    DataTable myDataTable = new DataTable();
 
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
 
    RadGrid1.DataSource = myDataTable;
}

The problem with that approach is that it needs to return all the data from database to let the grid make further data processing. What would you recommend to change in  the code snippet above if there is a million customer records in database and you need to implement paging, sorting and filtering and grouping on each field?
Princy
Top achievements
Rank 2
 answered on 16 Apr 2014
11 answers
755 views
Hi,
I was trying to use your CommandItemSettings to automatically display the Update and Delete buttons, like the AddNewRecordButton, but there is no such option available, I was wondering why? It would be useful to have those buttons available that would apply the command to the selected items in the grid, instead of having to add all to the CommandItemTemplate. These are common operations that one does in the grid...

Regards, Ariel
Princy
Top achievements
Rank 2
 answered on 16 Apr 2014
4 answers
119 views
I have a dropdownlist in template which is bound to a the db:

<telerik:RadDropDownList ID="RadDropDownList1" runat="server"  DataSourceID="SqlDataSource2"
          DataTextField="Pnum"  DataValueField="Pnum" SelectedValue='<%#Bind("Pnum") %>'>
         </telerik:RadDropDownList>

Then  I have a bound column "Project" that I would like to be automatically filled in when a value in the dropdown is selected based on a query:
Select Project from Pnum where Project = dropdown selected value, and save it.

How can I achieve that?
Your help will be appreciated.
Thanks,
Felice
Princy
Top achievements
Rank 2
 answered on 16 Apr 2014
1 answer
134 views
Hi,
i'm trying to detect the upload count on client side and determine if its 0.
If so i want to enable a panel. I've searched on the forum but cannot find a good example of how to detect upload count.

anyone have an example how to do this?

thanks
Shinu
Top achievements
Rank 2
 answered on 16 Apr 2014
2 answers
153 views
Hello, I am reviewing the commenting feature of the radeditor and have a few questions related to closing a comments dialog. For reference, I'm referring to http://demos.telerik.com/aspnet-ajax/editor/examples/comments/defaultcs.aspx. 

1. When a comment is clicked, the comment dialog pops up. Once the dialog is open, it seems that the comment dialog can be closed in one of two ways - either pressing the "cancel" button on the comment dialog once it appears, or, clicking somewhere in the editor outside of a comment. Is it possible out of the box to auto-close the comment dialog when clicking anywhere outside of the comment dialog, regardless of whether you click somewhere in the editor or out of the editor?

2. Is it possible out of the box to have a close widget on the comment dialog? 

Thanks
Shan
Shan
Top achievements
Rank 1
 answered on 16 Apr 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?