problem updating row in Gridview with bound combobox - asp.net

i have the following gridview
<asp:GridView ID="GridView3" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="CommentsDataSource">
<Columns>
<asp:BoundField DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname" />
<asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
<asp:BoundField DataField="Comment" HeaderText="Comment" />
<asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
<asp:TemplateField HeaderText="Approval">
<ItemTemplate>
<%#Eval("NewsCommentStatus.Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Eval("ApprovalStatusID") %>'
DataSourceID="CommentStatusDataSource" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" EditImageUrl="~/Admin/Theme/images/Icons/pencil.png"
EditText="Edit" />
</Columns>
</asp:GridView>
</ContentTemplate>
and the datasources are:
<asp:LinqDataSource ID="CommentsDataSource" runat="server" ContextTypeName="CMSSystem.Models.CMSDatabaseDataContext"
TableName="NewsComments" Where="NewsID == #NewsID" EnableUpdate="True">
<WhereParameters>
<asp:SessionParameter Name="NewsID" SessionField="NewsItemID" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="CommentStatusDataSource" runat="server" ContextTypeName="CMSSystem.Models.CMSDatabaseDataContext"
TableName="NewsCommentStatus">
</asp:LinqDataSource>
the problem im having is when the combobox is changed the value is not being updated is there something obvious i've missed?

Use Bind instead of Eval. Bind is used for two way databinding :
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("ApprovalStatusID") %>'
DataSourceID="CommentStatusDataSource" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>

Related

ASP.NET GridView with DRopDown list check if user updated/ changed the dropdown selection

I have a GridView that the user can edit, in particular a datafield (MemberApproved) is displayed as a dropdown list when edited.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" CssClass="gridview" AllowSorting="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" >
<HeaderStyle Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
<asp:BoundField DataField="Affiliation" HeaderText="Affiliation" SortExpression="Affiliation" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="MembershipCategory" HeaderText="Membership Category" SortExpression="MembershipCategory" />
<asp:TemplateField HeaderText="MemberApproved" SortExpression="MemberApproved">
<EditItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("MemberApproved") %>'></asp:HiddenField>
<asp:DropDownList ID="ddlStatus" runat="server"
SelectedValue='<%# Bind("MemberApproved") %>'>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
<asp:ListItem Value="Locked">Locked</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MemberApproved") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SupportingMember" HeaderText="Reference Member" SortExpression="SupportingMember" />
<asp:BoundField DataField="ReferenceEmail" HeaderText="Reference Email" SortExpression="ReferenceEmail" />
</Columns>
<HeaderStyle CssClass="fixedHeader " />
</asp:GridView>
I am trying to capture if the user changes the "MemberApproved" field, in the . I am able to capture the updated new value using the code below
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatus");
string NewSelection = ddl.SelectedValue;
}
I am however unable to hold the initial value of the dropdownlist in a variable to compare it to the NewSelection.
Any thoughts or suggestion to different approaches are greatly appreciated.
You're using a template field already. Why not store your value as part of a hiddenfield and then compare to it?
<asp:TemplateField HeaderText="MemberApproved" SortExpression="MemberApproved">
<EditItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("MemberApproved") %>'></asp:HiddenField>
<asp:DropDownList ID="ddlStatus" runat="server"
SelectedValue='<%# Bind("MemberApproved") %>'>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
<asp:ListItem Value="Locked">Locked</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MemberApproved") %>'></asp:Label>
<asp:hiddenField ID="label1History" runat="server" value='<%# Bind("MemberApproved") %>'
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatus");
HiddenField labelHistory = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("label1History");
string NewSelection = ddl.SelectedValue;
Boolean changedValue = NewSelection = labelHistory.value;
}

Cascading DropDownList binding in ASP.Net DetailsView templated control not working

I have two dropdown lists inside DetailsView, first dropdown DepartmentDropDown loads the data successfully from code behind using the following datasource
<asp:ObjectDataSource ID="dsDepartments" runat="server" SelectMethod="GetDepartments"
TypeName="MyCode.DepartmentEmployeeAssociations">
</asp:ObjectDataSource>
and the second dropdown EmployeeDropDown uses another datasource based on Department selection in the first dropdown (commented code works and loads the details view but not the control parameter code):
<asp:ObjectDataSource ID="dsEmployees" runat="server" SelectMethod="GetAllEmployees"
TypeName="MyCode.DepartmentEmployeeAssociations" DataObjectTypeName="Employee">
<SelectParameters>
<%--<asp:Parameter Name="deptId" Type="Int32" DefaultValue="7" />--%>
<asp:ControlParameter ControlID="DepartmentDropDown" Name="deptId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Here is the code in my GridView and DetailsView
<asp:Panel ID="AssociationView" runat="server" Visible="false">
<asp:GridView ID="gvAssociations" runat="server" AutoGenerateColumns="False" CssClass="GridViewStyle"
EmptyDataText="No rules defined" Width="100%" AllowPaging="True" GridLines="None"
DataKeyNames="Id" EnableModelValidation="True" DataSourceID="dsAssociations"
OnSelectedIndexChanged="gvAssociations_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="true" SelectText="View" ItemStyle-Width="50px">
<ItemStyle Width="50px"></ItemStyle>
</asp:CommandField>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="False" />
<asp:BoundField DataField="Value1" HeaderText="Employee" SortExpression="Value1" Visible="false" />
<asp:BoundField DataField="Value1Description" HeaderText="Employee" NullDisplayText="*" />
<asp:BoundField DataField="Value2" HeaderText="Department" SortExpression="Value2" Visible="false" />
<asp:BoundField DataField="Value2Description" HeaderText="Department" NullDisplayText="*" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<div class="DetailsContainer">
<asp:DetailsView ID="dvAssociations" runat="server" Height="50px" GridLines="None"
CellPadding="5" AutoGenerateRows="False" DataKeyNames="sId" EnableModelValidation="True"
OnItemCreated="dvAssociations_ItemCreated" OnItemUpdating="dvAssociations_ItemUpdating"
OnItemInserting="dvAssociations_ItemInserting">
<Fields>
<asp:BoundField DataField="Id" HeaderText="ID" ReadOnly="True" InsertVisible="False" Visible="false" />
<asp:TemplateField HeaderText="Department">
<ItemTemplate>
<asp:DropDownList ID="DepartmentDropDown" runat="server" SelectedValue='<%# Bind("Value2") %>'
DataSourceID="dsDepartments" DataValueField="DepartmentId" DataTextField="Name"
Enabled="false" AutoPostBack="true">
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DepartmentDropDown" runat="server" SelectedValue='<%# Bind("Value2") %>'
DataSourceID="dsDepartments" DataValueField="DepartmentId" DataTextField="Name"
Enabled="true" AutoPostBack="true">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DepartmentDropDown" runat="server" SelectedValue='<%# Bind("Value2") %>'
DataSourceID="dsDepartments" DataValueField="DepartmentId" DataTextField="Name"
Enabled="true" AutoPostBack="true">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee">
<ItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server"
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName"
Enabled="false">
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server"
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName"
Enabled="true">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server"
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName"
Enabled="true">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" ShowDeleteButton="True" />
</Fields>
</asp:DetailsView>
</div>
</asp:Panel>
and the code behind:
protected void gvAssociations_SelectedIndexChanged(object sender, EventArgs e)
{
dvAssociations.PageIndex = gvAssociations.SelectedRow.DataItemIndex;
}
protected void dvAssociations_ItemCreated(object sender, EventArgs e)
{
if (dvAssociations.DataItem == null)
return;
// Some checks
}
protected void dvAssociations_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
//some code
}
protected void dvAssociations_ItemInserting(object sender, DetailsViewUpdateEventArgs e)
{
e.NewValues["Value1"] = ((DropDownList)((DetailsView)sender).FindControl("EmployeeDropDown")).SelectedValue;
}
public List<Department> GetDepartments()
{
// code to return List<Department> departments
// other code
return departments;
}
public List<Employee> GetAllEmployees(int deptId)
{
// code to return List<Employee> employees
// other code
return employees;
}
I tried various suggestions that were given in other SO articles, but still not able to make this work. My page don't load when I have the control parameter added, but it works if I change it to a normal parameter.
<asp:ControlParameter ControlID="DepartmentDropDown" Name="deptId" PropertyName="SelectedValue" Type="Int32" />
I am not sure what it doesn't like about it, it doesn't seem to bind the data in the details view. I added the AutoPostBack to true to the first dropdown and removed the SelectedValue='<%# Bind("Value1") %>' from the second dropdown as suggested in other posts, but nothing seems to be working.
Any help would be appreciated.
I have finally made it work, it was a silly mistake but again I haven't worked on these asp components before. So, there was some learning here and hope this will help someone having similar issue.
Firstly, make sure that your data in the GridView is correct and the dropdown column has valid value and is in the dropdown list source.
Secondly, I had to move my ObjectDataSource for employees with in the itemtemplate
<asp:TemplateField HeaderText="Employee">
<ItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server" SelectedValue='<%# Bind("Value1") %>'
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName" Enabled="false">
</asp:DropDownList>
<asp:ObjectDataSource ID="dsEmployees" runat="server" SelectMethod="GetAllEmployees"
TypeName="MyCode.DepartmentEmployeeAssociations" DataObjectTypeName="Employee">
<SelectParameters>
<asp:ControlParameter ControlID="DepartmentDropDown" Name="deptId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server" SelectedValue='<%# DataBinder.Eval (Container.DataItem, "Value1") %>'
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName"
Enabled="true">
</asp:DropDownList>
<asp:ObjectDataSource ID="dsEmployees" runat="server" SelectMethod="GetAllEmployees"
TypeName="MyCode.DepartmentEmployeeAssociations" DataObjectTypeName="Employee">
<SelectParameters>
<asp:ControlParameter ControlID="DepartmentDropDown" Name="deptId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="EmployeeDropDown" runat="server" SelectedValue='<%# DataBinder.Eval (Container.DataItem, "Value1") %>'
DataSourceID="dsEmployees" DataValueField="EmployeeId" DataTextField="FullName"
Enabled="true">
</asp:DropDownList>
<asp:ObjectDataSource ID="dsEmployees" runat="server" SelectMethod="GetAllEmployees"
TypeName="MyCode.DepartmentEmployeeAssociations" DataObjectTypeName="Employee">
<SelectParameters>
<asp:ControlParameter ControlID="DepartmentDropDown" Name="deptId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</InsertItemTemplate>
</asp:TemplateField>
Also, I have replaced SelectedValue='<%# Bind("Value1") %>' to SelectedValue='<%# DataBinder.Eval (Container.DataItem, "Value1") %>' in my EmployeeDropDown aspx code to make it simpler. Which means, no need to add this event handler dvAssociations_ItemInserting to the DetailsView.
But, I have another issue related to orphan data in the grid, which doesn't exist in the dropdown - which make the ItemTemplate fail to load. That's for another post, this post is done for now. Hope it helps other.

Missing GridView vertical line. How to add it. in asp.net C# and Telerik

I'm running my code all alright. I've created the table that you see on the picture, but I can't see the line new Straight Line HeaderText.
I'm using ASP.net C# with Telerik.
** But What am I missing to display that line?**
Please help!
**GridView Code **
<div id="divMainGrid" runat="server" style="height: 700px">
<p>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" GridLines="None" ToolTip="Click on a row to select a setting." AllowPaging="true"
CssClass="AddBorders" ShowFooter="false" Width="100%" AllowFilteringByColumn="true" AllowSorting="true"
Visible="true"
OnDetailTableDataBind="RadGrid1_DetailTableBind"
OnNeedDataSource="radGrid_DataSource"
EnableHierarchyExpandAll="false">
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<ClientSettings EnablePostBackOnRowClick="false" EnableRowHoverStyle="true" AllowColumnsReorder="true">
<Resizing AllowColumnResize="false" />
<Selecting AllowRowSelect="false" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" EnableVirtualScrollPaging="false" ScrollHeight="490px" FrozenColumnsCount="3" />
</ClientSettings>
<GroupingSettings CaseSensitive="false" />
<MasterTableView Width="100%" DataKeyNames="AssetClass_ID, AssetCategory_ID" TableLayout="Fixed">
<ColumnGroups>
<telerik:GridColumnGroup Name="DepreciationAmortisationMethod" HeaderText="Depreciation/Amortisation Method" HeaderStyle-HorizontalAlign="Center">
</telerik:GridColumnGroup>
<telerik:GridColumnGroup Name="MeasurementModel" HeaderText="Measurement Model" HeaderStyle-HorizontalAlign="Center">
</telerik:GridColumnGroup>
<telerik:GridColumnGroup Name="RevaluationModel" HeaderText="Revaluation Model" HeaderStyle-HorizontalAlign="Center">
</telerik:GridColumnGroup>
</ColumnGroups>
<DetailTables>
<telerik:GridTableView DataKeyNames="AssetClass_ID, AssetCategory_ID" Name="CategoryDetails" EnableHierarchyExpandAll="false" HierarchyLoadMode="ServerOnDemand" AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn DataField="AssetCategory_ID" HeaderText="Asset Category ID" UniqueName="AssetCategory_ID" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="5px" Visible="false" />
<telerik:GridBoundColumn DataField="CategoryDescription" HeaderText="Asset Category Description" UniqueName="CategoryDescription" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="104px" />
<%--
'>
<telerik:GridTemplateColumn ColumnEditorID="colEditMonths" DataField="UsefulLifeMonth" HeaderText="Months" UniqueName="Months" HeaderStyle-Width="85px" ColumnGroupName="UsefulLife">
<ItemTemplate>
<asp:TextBox ID="txtMonths" runat="server" Width="85px" ReadOnly="false" ViewStateMode="Enabled" Text='<%# Eval("UsefulLifeMonth").ToString()%>'></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>--%>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn ColumnEditorID="colEditChkbox" HeaderText="Select" UniqueName="SelectAsset" AllowFiltering="false" HeaderStyle-Width="45px" >
<ItemTemplate>
<asp:CheckBox ID="chkSelectAsset" runat="server" Text="Select" EnableViewState="true" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="AssetClass_ID" HeaderText="Asset Class ID" UniqueName="AssetClass_ID" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="5px" Visible="false" />
<telerik:GridBoundColumn DataField="AssetClassDescription" HeaderText="Asset Class Description" UniqueName="AssetCategory_ID" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="175px" Visible="true" ColumnGroupName="DepreciationAmortisationMethod" />
<telerik:GridTemplateColumn ColumnEditorID="colEdit_StraightLineID" DataField="StraightLine" HeaderText="Straight Line" UniqueName="StraightLineID" AllowFiltering="false" HeaderStyle-Width="140px" ItemStyle-VerticalAlign="Top" ColumnGroupName="DepreciationAmortisationMethod">
<ItemTemplate>
<asp:RadioButton ID="rdbStraightLine" runat="server" CausesValidation="true" GroupName="DepreciationAmortisationMethod" Checked='<%# Convert.ToBoolean(Eval("StraightLine")) == false ? false : Convert.ToBoolean(Eval("StraightLine"))%>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_DiminishingBalanceInitialYear" DataField="DiminishingBalanceInitialYear" HeaderText="Diminishing Balance Initial Year" UniqueName="DiminishingBalanceInitialYear" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="DepreciationAmortisationMethod">
<ItemTemplate>
<asp:RadioButton ID="rdbDiminishingBalanceInitialYear" runat="server" CausesValidation="true" GroupName="DepreciationAmortisationMethod" Checked='<%# Convert.ToBoolean(Eval("DiminishingBalanceInitialYear")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_DiminishingBalanceSubsequentYear" DataField="DiminishingBalanceSubsequentYear" HeaderText="Diminishing Balance SubsequentYear" UniqueName="DiminishingBalanceSubsequentYear" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="DepreciationAmortisationMethod">
<ItemTemplate>
<asp:RadioButton ID="rdbDiminishingBalanceSubsequentYear" runat="server" CausesValidation="true" GroupName="DepreciationAmortisationMethod" Checked='<%# Convert.ToBoolean(Eval("DiminishingBalanceSubsequentYear")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_UnitsOfProduction" DataField="UnitsOfProduction" HeaderText="Units Of Production" UniqueName="UnitsOfProduction" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="DepreciationAmortisationMethod">
<ItemTemplate>
<asp:RadioButton ID="rdbUnitsOfProduction" runat="server" CausesValidation="true" GroupName="DepreciationAmortisationMethod" Checked='<%# Convert.ToBoolean(Eval("UnitsOfProduction")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_Cost" DataField="Cost" HeaderText="Cost" UniqueName="Cost" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="MeasurementModel">
<ItemTemplate>
<asp:RadioButton ID="rdbCost" runat="server" CausesValidation="true" GroupName="MeasurementModel" Checked='<%# Convert.ToBoolean(Eval("Cost")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_RevaluedAmount" DataField="RevaluedAmount" HeaderText="RevaluedAmount" UniqueName="RevaluedAmount" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="MeasurementModel">
<ItemTemplate>
<asp:RadioButton ID="rdbRevaluedAmount" runat="server" CausesValidation="true" GroupName="MeasurementModel" Checked='<%# Convert.ToBoolean(Eval("RevaluedAmount")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_FairValue" DataField="FairValue" HeaderText="Fair Value" UniqueName="FairValue" AllowFiltering="false" HeaderStyle-Width="140px" ColumnGroupName="MeasurementModel">
<ItemTemplate>
<asp:RadioButton ID="rdbFairValue" runat="server" CausesValidation="true" GroupName="MeasurementModel" Checked='<%# Convert.ToBoolean(Eval("FairValue")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_DepreciationProportionately" DataField="DepreciationProportionately" HeaderText="Restatement of Accumulated Depreciation Proportionately" UniqueName="DepreciationProportionately" AllowFiltering="false" HeaderStyle-Width="180px" ColumnGroupName="RevaluationModel">
<ItemTemplate>
<asp:RadioButton ID="rdbDepreciationProportionately" runat="server" CausesValidation="true" GroupName="RevaluationModel" Checked='<%# Convert.ToBoolean(Eval("DepreciationProportionately")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="colEdit_AccumulatedDepreciation" DataField="AccumulatedDepreciation" HeaderText="Accumulated Depreciation Eliminated against Gross Carrying Amount of the Asset" UniqueName="AccumulatedDepreciation" AllowFiltering="false" HeaderStyle-Width="180px" ColumnGroupName="RevaluationModel">
<ItemTemplate>
<asp:RadioButton ID="rdbAccumulatedDepreciation" runat="server" CausesValidation="true" GroupName="RevaluationModel" Checked='<%# Convert.ToBoolean(Eval("AccumulatedDepreciation")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<FilterMenu EnableImageSprites="False" />
</telerik:RadGrid>
</p>
</div>
GridView Image
I know there used to be some issues with static headers and frozen columns when used together, but I think they are resolved. Try the latest version (at the time of writing: 2015.1.225 in numbers, Q1 2016 SP1 in "words") and perhaps things will be fine. If not, open a ticket with Telerik.

Using Eval If/Else/EndIf in GridView causes error Databinding methods such as Eval(), XPath(), and Bind()

I am trying to pro grammatically alter a value in a GridView based on a returned database value.
The database value "is_zero_minutes_task" is Boolean. If True I wish to display a "0" and if False I wish to display the value returned in "MinutesTaken".
My code:
<asp:SqlDataSource ID="SqlDataSourceRecentJobs" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString_LIVE_customer_support %>"
ProviderName="<%$ ConnectionStrings:ConnectionString_LIVE_customer_support.ProviderName %>"
SelectCommand="SELECT customer_name, start_time, end_time, is_zero_minutes_task, TIMESTAMPDIFF(MINUTE,start_time,end_time) AS MinutesTaken FROM time_recorder_jobs WHERE (time_recorder_jobs.deleted = #deleted) AND (time_recorder_users.company_id = #companyid) ORDER BY end_time">
<SelectParameters>
<asp:Parameter Name="#deleted" DefaultValue="0" Type="Object" />
<asp:SessionParameter Name="companyid" SessionField="CompanyID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridViewRecentJobs" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSourceRecentJobs" ForeColor="#333333"
GridLines="None" CellSpacing="4" ShowHeaderWhenEmpty="True"
AllowSorting="True" AllowPaging="True">
<Columns>
<asp:BoundField DataField="customer_name" HeaderText="customer_name"
SortExpression="customer_name">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="start_time" HeaderText="start_time"
SortExpression="start_time">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="end_time" HeaderText="end_time"
SortExpression="end_time">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:TemplateField HeaderText="MinutesTaken" SortExpression="MinutesTaken">
<ItemTemplate>
<%If Eval("is_zero_minutes_task").ToString = True Then%>
<asp:Label ID="MinutesTaken" runat="server" Text="0"></asp:Label>
<%Else%>
<asp:Label ID="MinutesTaken" runat="server" Text='<%# Bind("MinutesTaken") %>'></asp:Label>
<%End If%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I also tried using:
<%If DataBinder.Eval(GridViewRecentJobs.DataItem, "is_zero_minutes_task") = True Then%>
But that presents the error of "'DataItem' is not a member of System.Web.UI.WebControls.GridView'"
I worked it out!
<asp:TemplateField HeaderText="MinutesTaken" SortExpression="MinutesTaken">
<ItemTemplate>
<asp:Label ID="MinutesTaken" runat="server" Text='<%# If((Eval("is_zero_minutes_task") = 1), "0", Eval("MinutesTaken"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Drop down in detailsview not updating to database

I have fields for a contact. 3 of those fields are drop downs to values from another table in the database. For example, Contacts has the foreign key for departmentid which pulls from the department table to get the description. But when i click the Edit and update, this does not update my database. It acts like nothing happened.
EDIT: Just noticed this, but when i change the name and click update. I get an error telling me that EmployerCode cannot be set to null. I know that the database is set to not nullable. But i do not understand why the original value is not being pulled. When i load the contact, all three of the drop downs have values from the database loaded. Although i am seeing that all three are displaying the first item in the table and not the item the contact has in it's values. But when editing the contact, it acts like those values are not loaded and are just null.
<asp:DetailsView ID="detailsViewContact" runat="server" Height="90px" Width="293px"
DataSourceID="ContactDataSource" AutoGenerateRows="False"
BackColor="#FFCC66" BorderStyle="None" BorderWidth="0px" CellPadding="3"
DataKeyNames="ContactID" Font-Bold="True" HorizontalAlign="Center">
<CommandRowStyle BackColor="White" BorderColor="White" Font-Bold="True"
Font-Size="Large" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="SSOID" HeaderText="SSOID"
SortExpression="SSOID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="Lastname" HeaderText="Lastname"
SortExpression="Lastname" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State"
SortExpression="State" />
<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"
SortExpression="ZipCode" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" />
<asp:TemplateField HeaderText="AccessRightID" SortExpression="AccessRightID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList10" Enabled="false" runat="server"
DataSourceID="AccessRightDataSource" DataTextField="AccessRightDescription"
DataValueField="AccessRightID">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployerCode" SortExpression="EmployerCode">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" Enabled="false" runat="server"
DataSourceID="EmployerDataSource" DataTextField="EmployerName"
DataValueField="EmployerCode">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DepartmentID" SortExpression="DepartmentID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList8" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList9" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList7" Enabled="false" runat="server"
DataSourceID="DepartmentDataSource" DataTextField="Description"
DataValueField="DepartmentID">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
here are my datasources
<asp:EntityDataSource ID="EmployerDataSource" runat="server"
ConnectionString="name=WorkStudyEntities"
DefaultContainerName="WorkStudyEntities" EnableFlattening="False"
EntitySetName="Employers" EnableUpdate="True">
It looks like this was a fluke somehow. I redid the page and it all worked correctly

Resources