Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:19:01+00:00 2026-06-13T08:19:01+00:00

I got this strange error when i want to bind something in my grid

  • 0

I got this strange error when i want to bind something in my grid from my db
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.

<%@ Page Title="" Language="C#" MasterPageFile="~/ABBMaster.Master" AutoEventWireup="true"
    CodeBehind="UserEditPanel.aspx.cs" Inherits="HolidayTracker.Administrator.UserEditPanel" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainRegionContentPlaceHolder" runat="server">
    <telerik:RadScriptManager ID="rsmTelerik" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js"></asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js"></asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js"></asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>


    <br />
    <%-- Export script %>
    <%--    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>--%>
    <asp:Panel ID="pnlContent" CssClass="pnlContent" runat="server">

        <asp:Panel ID="pnlHeader" CssClass="pnlHeader" runat="server">
        </asp:Panel>
        <asp:Panel ID="pnlBody" CssClass="pnlBody" runat="server">
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Skin="Default" LoadingPanelID="RadAjaxLoadingPanel1">
                <fieldset style="padding: 10px; margin-bottom: 10px;">
                    <legend>User form</legend>
                    <div class="formRowDiv">
                        <asp:Label ID="label4" CssClass="formLabel" runat="server" Text="Email"></asp:Label>

                        <telerik:RadComboBox ID="rcbSearch" CssClass="rowForm" runat="server" Width="260px"
                            Height="100px" EmptyMessage="Enter Email" EnableLoadOnDemand="true" AutoPostBack="true" AllowCustomText="true" MarkFirstMatch="true"
                            OnItemsRequested="rcbSearch_ItemsRequested" CausesValidation="false" OnSelectedIndexChanged="rcbSearch_IndexChanged" Skin="Default">
                        </telerik:RadComboBox>
                        <asp:RegularExpressionValidator ID="revEmail" runat="server" Display="Dynamic" ControlToValidate="rcbSearch"
                            ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
                            ErrorMessage="Enter a valid email address" />
                        <asp:RequiredFieldValidator ID="rfvEmail" runat="server" Display="Dynamic" ControlToValidate="rcbSearch"
                            ErrorMessage="Can not be empty" CssClass="rowFormValidation" />
                    </div>
                    <div class="formRowDiv">
                        <asp:Label ID="label1" CssClass="formLabel" runat="server" Text="Firstname"></asp:Label>
                        <telerik:RadTextBox ID="rtbFirstName" CssClass="rowForm" runat="server" ReadOnly="false" />
                        <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" Display="Dynamic" ControlToValidate="rtbFirstName"
                            ErrorMessage="Can not be empty" CssClass="rowFormValidation" />
                    </div>
                    <div class="formRowDiv">
                        <asp:Label ID="label2" CssClass="formLabel" runat="server" Text="Lastname"></asp:Label>
                        <telerik:RadTextBox ID="rtbLastName" CssClass="rowForm" runat="server" ReadOnly="false" />
                        <asp:RequiredFieldValidator ID="rfvLastName" runat="server" Display="Dynamic" ControlToValidate="rtbLastName"
                            ErrorMessage="Can not be empty" CssClass="rowFormValidation" />
                    </div>
                    <div class="formRowDiv">
                        <asp:Label ID="label3" CssClass="formLabel" runat="server" Text="Username"></asp:Label>
                        <telerik:RadTextBox ID="rtbUserName" CssClass="rowForm" runat="server" ReadOnly="false" />
                        <asp:RequiredFieldValidator ID="rfvUserName" runat="server" Display="Dynamic" ControlToValidate="rtbUserName"
                            ErrorMessage="Can not be empty" CssClass="rowFormValidation" />
                    </div>
                    <div class="formRowDiv" style="display: none;">
                        <asp:Label ID="label5" CssClass="formLabel" runat="server" Text="AdAccount"></asp:Label>
                        <telerik:RadTextBox ID="rtbAdAccount" CssClass="rowForm" runat="server" ReadOnly="false" />
                    </div>
                    <div class="formRowDiv" style="display: none;">
                        <asp:Label ID="label6" CssClass="formLabel" runat="server" Text="AdDomain"></asp:Label>
                        <telerik:RadTextBox ID="rtbAdDomain" CssClass="rowForm" runat="server" ReadOnly="True" />
                    </div>
                    <div class="formRowDiv">
                        <asp:Label ID="label8" runat="server" Text="Role" CssClass="formLabel"></asp:Label>
                        <telerik:RadComboBox ID="rcbUserRoles" CssClass="rowForm" CheckBoxes="True" EmptyMessage="- Please select -"
                            runat="server" DataTextField="Name" DataValueField="RoleId">
                        </telerik:RadComboBox>
                        <asp:SqlDataSource ID="UserRoleSqlSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                            SelectCommand="SELECT * FROM [HtUserRole]"></asp:SqlDataSource>
                    </div>
                    <div class="formRowDiv">
                        <%--  <asp:Label ID="label7" CssClass="formLabel" runat="server" Text="Annual vacations"></asp:Label> --%>
                        <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">

                            <telerik:RadGrid ID="rgAnnualVacation" runat="server" CellSpacing="0" GridLines="None" AllowPaging="True" AutoGenerateDeleteColumn="True"
                                OnInsertCommand="rgAnnualVacation_InsertCommand" OnDeleteCommand="rgAnnualVacation_DeleteCommand" Height="200px"
                                OnUpdateCommand="rgAnnualVacation_UpdateCommand" OnNeedDataSource="rgAnnualVacation_NeedDataSource">

                                <MasterTableView AutoGenerateColumns="false" DataKeyNames="AnnualVacationId" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">

                                    <Columns>
                                        <telerik:GridBoundColumn DataField="AnnualVacationId" Visible="false" DataType="System.Int32" FilterControlAltText="Filter AnnualVacationId column" HeaderText="AnnualVacationId" ReadOnly="True" SortExpression="AnnualVacationId" UniqueName="AnnualVacationId">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="UserId" Visible="false" DataType="System.Int32" FilterControlAltText="Filter UserId column" HeaderText="UserId" SortExpression="UserId" UniqueName="UserId">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="FromDate" DataType="System.DateTime" FilterControlAltText="Filter FromDate column" HeaderText="FromDate" SortExpression="FromDate" UniqueName="FromDate">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="ToDate" DataType="System.DateTime" FilterControlAltText="Filter ToDate column" HeaderText="ToDate" SortExpression="ToDate" UniqueName="ToDate">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="WorkingTime" DataType="System.Int32" FilterControlAltText="Filter WorkingTime column" HeaderText="WorkingTime" SortExpression="WorkingTime" UniqueName="WorkingTime">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="VacationDays" DataType="System.Double" FilterControlAltText="Filter VacationDays column" HeaderText="VacationDays" SortExpression="VacationDays" UniqueName="VacationDays">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridEditCommandColumn />
                                    </Columns>

                                    <EditFormSettings EditFormType="Template">
                                        <FormTemplate>
                                            <table>
                                                <tr>
                                                    <td>From</td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="fromdatepicker" runat="server" MaxDate="1/1/2015" DbSelectedDate='<%# Eval("fromdate") == null ? null : Eval("fromdate") %>' TabIndex="4">
                                                        </telerik:RadDatePicker>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>To</td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="todatepicker" runat="server" MinDate="1/1/1900" DbSelectedDate='<%# Eval("todate") == null ? null :Eval("todate")%>'
                                                            TabIndex="4">
                                                        </telerik:RadDatePicker>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Working time (%)</td>
                                                    <td>
                                                        <telerik:RadNumericTextBox ID="txtWorkingTime" runat="server" NumberFormat-DecimalDigits="0" DbValue='<%# Bind("WorkingTime") %>'></telerik:RadNumericTextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Vacation days</td>
                                                    <td>
                                                        <telerik:RadNumericTextBox ID="txtVacationDays" runat="server" NumberFormat-DecimalDigits="2" DbValue='<%# Bind("VacationDays") %>'></telerik:RadNumericTextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                            <table style="margin-top: 15px;">
                                                <tr>
                                                    <td>
                                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                                    </td>
                                                    <td>
                                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                            CommandName="Cancel"></asp:Button>
                                                    </td>
                                                </tr>
                                            </table>
                                        </FormTemplate>
                                    </EditFormSettings>
                                    <%--<CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true" ShowExportToCsvButton="true" />--%>
                                </MasterTableView>
                                <FilterMenu EnableImageSprites="False">
                                </FilterMenu>
                            </telerik:RadGrid>
                        </telerik:RadAjaxPanel>
                    </div>
                    <div class="formRowDiv">
                        <telerik:RadButton ID="rbBack" CssClass="rowButton" runat="server" Text="Back" OnClick="rbBack_Clicked"
                            CausesValidation="false" />
                        <telerik:RadButton ID="rbSave" CssClass="rowButton" runat="server" Text="Save" OnClick="rbSave_Clicked" />
                    </div>
                </fieldset>
            </telerik:RadAjaxPanel>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
            </telerik:RadAjaxLoadingPanel>
        </asp:Panel>
        <asp:Panel ID="pnlFooter" CssClass="pnlFooter" runat="server">
        </asp:Panel>
    </asp:Panel>
</asp:Content>






using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HolidayTracker.Data.Model;
using Telerik.Web.UI;
using HolidayTracker.Code;
using System.Collections;

namespace HolidayTracker.Administrator
{
    public partial class UserEditPanel : System.Web.UI.Page
    {

        private List<AnnualVacation> annualVacations = new List<AnnualVacation>();

        private Boolean newUser;
        private HtUser paramUser;
        private HtUser user;
        private HtUser User
        {
            get
            {
                user = HtUser.INIT_USER(this.Page, true);
                return user;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            getParameters();
            if (!IsPostBack)
            {

                bindData();

                fillFieldsWithData();
                initFieldSettings();
            }
        }

        private void getParameters()
        {
            if (Page.Request["userId"] != null)
            {
                int userId = Constants.TryConvert(Page.Request["userId"], this.Page);
                this.paramUser = HtUser.GetById(userId);
            }
            else
            {
                this.paramUser = new HtUser();
            }
        }

        private void initFieldSettings()
        {
            if (!newUser)
            {
                //this.rcbSearch.Enabled = false;
            }
        }

        private void bindData()
        {
            this.rcbUserRoles.DataSource = this.UserRoleSqlSource;
            this.rcbUserRoles.DataBind();

            //fill viewstate with annual vacations if empty
            if (paramUser != null && paramUser.AnnualVacations.Any())
            {
                if (ViewState["AnnualVacationSource"] == null)
                {
                    annualVacations.AddRange(paramUser.AnnualVacations);
                    ViewState["AnnualVacationSource"] = annualVacations;
                }
            }
        }

        private void fillFieldsWithData()
        {
            if (paramUser != null)
            {
                this.rtbFirstName.Text = paramUser.FirstName;
                this.rtbLastName.Text = paramUser.LastName;
                this.rtbUserName.Text = paramUser.UserName;
                this.rcbSearch.Text = paramUser.Email;
                this.rtbAdAccount.Text = paramUser.AdAccount;
                this.rtbAdDomain.Text = paramUser.AdDomain;

                //UserRole
                IEnumerable<HtUserRole> userRoles = paramUser.HtUserRoles != null ? paramUser.HtUserRoles : null;
                if (userRoles != null && userRoles.Count() > 0)
                {
                    foreach (RadComboBoxItem rcbi in rcbUserRoles.Items)
                    {
                        rcbi.Checked = false;
                        foreach (HtUserRole ur in userRoles)
                        {
                            if (ur.RoleId.ToString() == rcbi.Value)
                            {
                                rcbi.Checked = true;
                                break;
                            }
                        }
                    }
                }
            }
        }

        protected void rcbSearch_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            if (e.Text != null && e.Text.Length > 2)
            {
                IEnumerable<HtUser> result = null;
                AdLookup lookup = new AdLookup();
                result = lookup.SearchAdUserByEmail(e.Text);//HtUser.SearchByEmail(e.Text);
                if (result != null && result.Count() > 0)
                {
                    foreach (HtUser user in result)
                    {
                        this.rcbSearch.Items.Add(new RadComboBoxItem(user.Email, user.UserId.ToString()));
                    }
                }
            }
        }

        protected void rcbSearch_IndexChanged(object sneder, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            string email = e.Text;
            AdLookup lookup = new AdLookup();
            paramUser = lookup.GetAdUserByEmail(email);
            fillFieldsWithData();
        }

        private void saveData()
        {
            HolidayTrackerEntities ctx = HtEntityFactory.Context;
            HtUser userToSave = ctx.HtUsers.Where(u => u.UserId == paramUser.UserId).FirstOrDefault();
            if (userToSave == null)
            {
                userToSave = new HtUser();
                userToSave.IsNew = true;
            }
            userToSave.FirstName = this.rtbFirstName.Text;
            userToSave.LastName = this.rtbLastName.Text;
            userToSave.UserName = this.rtbUserName.Text;
            userToSave.Email = this.rcbSearch.Text;
            userToSave.AdAccount = this.rtbAdAccount.Text;
            userToSave.AdDomain = this.rtbAdDomain.Text;

            //UserRole
            foreach (RadComboBoxItem rcbi in rcbUserRoles.Items)
            {
                HtUserRole newUserRole = HtUserRole.GetById(int.Parse(rcbi.Value));

                if (rcbi.Checked)
                {
                    if (userToSave.HtUserRoles.Where(x => x.RoleId == newUserRole.RoleId).Count() == 0)
                    {
                        userToSave.HtUserRoles.Add(newUserRole);
                    }
                }
                else
                {
                    if (userToSave.HtUserRoles.Where(x => x.RoleId == newUserRole.RoleId).Count() > 0)
                    {
                        userToSave.HtUserRoles.Remove(newUserRole);
                    }
                }
            }

            if (userToSave.IsNew)
            {
                ctx.AddToHtUsers(userToSave);
            }

            if (((List<AnnualVacation>)ViewState["AnnualVacationSource"]) != null)
            {
                List<AnnualVacation> vacationToSave = (List<AnnualVacation>)ViewState["AnnualVacationSource"];
                IEnumerable<AnnualVacation> existing = paramUser.AnnualVacations;
                foreach (AnnualVacation toSave in vacationToSave)
                {
                    //if (toSave.IsNew) {
                    //    ctx.AddToAnnualVacations(toSave);
                    //}

                    //Zu löschende aus context löschen
                }
            }

            ctx.SaveChanges();
        }

        protected void rbBack_Clicked(object sender, EventArgs e)
        {
            Response.Redirect("~/Administrator/UserPanel.aspx");
        }

        protected void rbSave_Clicked(object sender, EventArgs e)
        {
            saveData();
            fillFieldsWithData();
        }

        protected void rgAnnualVacation_InsertCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem item = e.Item as GridEditableItem;
                Hashtable values = new Hashtable();
                item.ExtractValues(values);

                AnnualVacation newAnnualVacation = new AnnualVacation();
                item.UpdateValues(newAnnualVacation);
                //newAnnualVacation.IsNew = true;

                ((List<AnnualVacation>)ViewState["AnnualVacationSource"]).Add(newAnnualVacation);
            }
            catch
            {
                //Hier fehlermeldung
            }

        }

        protected void rgAnnualVacation_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            int annualVacationId = int.Parse((e.Item as GridDataItem).GetDataKeyValue("AnnualVacationId").ToString());
            ((List<AnnualVacation>)ViewState["AnnualVacationSource"]).
                Remove(((List<AnnualVacation>)ViewState["AnnualVacationSource"]).
                Where(av => av.AnnualVacationId == annualVacationId).FirstOrDefault());
        }

        protected void rgAnnualVacation_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            rgAnnualVacation.DataSource = ViewState["AnnualVacationSource"];
            if (rgAnnualVacation.DataSource == null)
            {
                rgAnnualVacation.DataSource = String.Empty;
            }
        }

        protected void rgAnnualVacation_UpdateCommand(object sender, GridCommandEventArgs e)
        {

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:19:02+00:00Added an answer on June 13, 2026 at 8:19 am

    Maybe datafields fromdate and todate are case sensitive. I see your GridBoundColumns use FromDate and ToDate. Have you tried that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a really strange error. This is the stacktrace that is coming from
I’ve got this strange problem whereby the content within a scroll viewer increases in
Got this error message while trying to load view: The model item passed into
Got this error message while trying to configure an entitydatasource in the designer: My
I've got this strange problem using py-amqp and the Flopsy module. I have written
I have got a strange problem.This is my code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I just randomly got this strange error via Rails 3, on heroku (postgres) PGError:
I have got this strange problem.XSL is not working with xml.This is my xml
I got this strange error on SVN: Error while updating filelist (The path '/path/'
I've got a strange error when I try to run this rvm install script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.