Drop down in detailsview not updating to database - asp.net

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

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;
}

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.

ASP.NET GridView Display TextBox if Row is Empty

My GridView is DataBound to a SQL data connection which should almost always return data. So using an EmptyDataTemplate does not help me because the GridView should never be empty. But I want the first few rows to be editable so the user can add new information to the GridView. So I've crafted my Select statement to always come back with 3 empty rows. I want those rows to contain TextBoxes instead of Labels. But this:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
BorderColor="White" BorderStyle="Solid"
onselectedindexchanged="GridView1_SelectedIndexChanged" ShowFooter="False"
ViewStateMode="Disabled">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" id ="CheckBox1" class="checkbox" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Serial" SortExpression="Serial">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Serial") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Model" SortExpression="Model">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Model") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="From Store">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="dropdownlist"
DataSourceID="SqlDataSource2" DataTextField="Store"
SelectedValue='<%# Bind("Store") %>'>
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="To Store">
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="dropdownlist"
DataSourceID="SqlDataSource2" DataTextField="Store">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle HorizontalAlign="Center" ForeColor="White" BorderColor="White" BorderStyle="Solid" />
<HeaderStyle ForeColor="White" BorderColor="White" BorderStyle="Solid" />
<RowStyle BorderColor="White" BorderStyle="Solid" ForeColor="White" />
</asp:GridView>
Produces this:
Where the first 3 rows have uneditable Labels rather than TextBoxes. Is what I want to do possible?
In your template fields add <FooterTemplate></FooterTemplate> This makes the footer row of your gridview a place where you can add new rows. Of course you will need to put items inside the <FooterTemplate>, but the work the same as your <ItemTemplates
So to serve my specific purpose, I decided just to create a table separate from this with an empty row with textboxes. Then a button that used JQuery to take the values from that table to append them into the uneditable row in the DataGrid. Removed the header row from the DataGrid so it all looked like the same table.

dropdown list in edit and read-only mode

Hello i have a dropdown list in edit mode and read only mode. If users upload pictures, i want them to chose a category for the uploaded pics and display it in a gridview as below.(See Picture below).
When i include "SelectedValue='<%# Bind("CategoryID")" in edit and item template mode, i get this error "'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value "
When i removed the "SelectedValue='<%# Bind("CategoryID")" from edit and item template, i get the result on the pic below(screenshot). If u can see the pic below the category is not selected, it just display the -- No Category -- even when i chose a category for the pic.
I want when a pic is uploaded and i category chosen, to display on the gridview. The code for the error message is below:
<EditItemTemplate>
<asp:DropDownList ID="pictureEditCategories" runat="server"
AppendDataBoundItems="True"
DataSourceID="categoriesDataSource"
DataTextField="Name" DataValueField="CategoryID"
SelectedValue='<%# Bind("CategoryID") %>' ValidationGroup="PictureEdit" >
<asp:ListItem Value="" Text="--No Category -- "/>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="PictureReadOnlyCategories" runat="server"
AppendDataBoundItems="True" DataSourceID="categoriesDataSource"
DataTextField="Name" DataValueField="CategoryID" Enabled="False"
SelectedValue='<%# Bind("CategoryID") %>' ValidationGroup="PictureEdit"
>
<asp:ListItem Value="">-- No Category --</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="False"
Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
ErrorMessage="must enter a title" ValidationGroup="PictureEdit"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Columns="25" Rows="4"
Text='<%# Bind("Description") %>' TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox2" Display="Dynamic"
ErrorMessage="you must enter a description" ValidationGroup="PictureEdit"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Added" SortExpression="UploadedOn">
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("UploadedOn") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("UploadedOn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageUrlField="PictureID"
DataImageUrlFormatString="~/UploadedImages/{0}.jpg" HeaderText="Image"
ReadOnly="True">
<ControlStyle Width="100px" />
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
When i remove the SelectedValue='<%# Bind("CategoryID") %>' from the item and edit template, I get the result for the picture below.
Please i will appreciate your help.
Please you can edit the code or explain it to me since im still learning ASP.net
question answered
You have a DataSource defined with a parameterized query that contains two parameters:
#CategoryID
#UserID
However, you appear to only be populating one of the parameters via the Control Parameters.
Fixing this should be easy enough as you are already pulling the UserID from a query string variable in your other DataSource. You should be able to just copy the QueryStringParameter into your list of SelectParameters for your photo DataSource. Highlighted below:
You could also handle the Selecting event of the datasource and programatically set the UserID in the query that way, but the aforementioned option is easiest. I just want you to be aware of all your options.

problem updating row in Gridview with bound combobox

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>

Resources