I have a gridview that, when in edit mode, I use a dropdown to load all provinces, however, when I change the province and click update, my page crashes...I'm not sending the province parameter to the gridview's updateparameters properly...here's my code, someone please help..
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="False" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="gvUsers_RowDataBound"
OnRowDeleting="gvUsers_RowDeleting" >
<HeaderStyle BackColor="#904601" ForeColor="White"
Font-Bold="True" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="Yellow" />
<AlternatingRowStyle BackColor="White" Font-Bold="false" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Select" runat="server">
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" Visible="False" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Left" />
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="SqlDataSource1" AutoGenerateRows="False" Width="85%" DataKeyNames="UserID"
HorizontalAlign="Center" AutoGenerateInsertButton="True" AutoGenerateEditButton="True" OnItemInserted="dvUsers_ItemInserted" >
<Fields>
<asp:BoundField DataField="UserID" Visible="False" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="true" SortExpression="UserName" />
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:Label runat="server" ID="lblPassword" Text="●●●●●●●●●"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password" Text='<%# Bind("Password") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birthdate" SortExpression="Birthdate">
<EditItemTemplate>
<asp:TextBox runat="server" ID="Birthdate" Text='<%# Bind("Birthdate") %>' ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="Server" ID="lblBirthdate" Text='<%# Bind("Birthdate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" SortExpression="Apt" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:TemplateField HeaderText="Province">
<ItemTemplate>
<asp:Label runat="server" ID="lblProvince" Text='<%# Eval("ProvName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlProvince" DataValueField="ProvinceID" DataSourceID="SqlDataSource2" DataTextField="Province"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" SortExpression="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:CheckBoxField DataField="ynAdminUser" HeaderText="ynAdminUser" SortExpression="ynAdminUser" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT ProvinceID, Province FROM tblProvince"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT a.UserID, a.FirstName, a.LastName, a.UserName, a.Password, a.Birthdate, a.Address, a.Apt, a.City, a.Province, b.Province as 'ProvName',
a.PostalCode, a.PhoneNum, a.Email, a.ynAdminUser
FROM tblUser a
INNER JOIN tblProvince B ON A.Province = B.ProvinceID
WHERE (a.UserID = #UserID) AND (a.ynDelete = 0)"
InsertCommand="INSERT INTO tblUser(FirstName, LastName, UserName, Password, Birthdate, Address, Apt, City, Province, PostalCode, Email, PhoneNum, ynAdminUser, ynDelete) VALUES (#FirstName, #LastName, #UserName, #Password, #Birthdate, #Address, #Apt, #City, #Province, #PostalCode, #Email, #PhoneNum, #ynAdminUser, 0)"
UpdateCommand="UPDATE tblUser SET FirstName = #FirstName, LastName = #LastName, Birthdate = #Birthdate, Address = #Address, Apt = #Apt, City = #City, Province = #Province, PostalCode = #PostalCode, PhoneNum = #PhoneNum, Email = #Email, ynAdminUser = #ynAdminUser WHERE (UserID = #UserID)">
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" Name="UserID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter DbType="DateTime" Name="BirthDate" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Apt" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:ControlParameter Name="Province" ControlID="ddlProvince" PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ynAdminUser" Type="Boolean" />
<asp:Parameter Name="UserID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter DbType="DateTime" Name="Birthdate" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Apt" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Province" Type="Int32" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="ynAdminUser" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
You don't need the control binding:
<asp:ControlParameter Name="Province" ControlID="ddlProvince" PropertyName="SelectedValue" Type="Int32" />
Instead, use a regualar parameter like your others and add the following binding to your drop-down list for the edit mode of the gridview:
SelectedValue=<%#Bind("Province")%>
I realize this is a really old question, and I hope you found your answer.
Looking at your markup, though, I want to say your connection strings were never filled out:
runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
I am not the strongest when it comes to ASP.NET databinding in the markup code, but I am pretty sure your connection string needs to point to an actual string name in your web.Config file's ConnectionStrings section:
<connectionStrings>
<clear />
<add name="Mark1" connectionString="Data Source=localhost;Initial Catalog=Table1;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Use whatever your actual connection string is, though.
Now, your markup should be written as:
runat="server" ConnectionString="<%$ ConnectionStrings:Mark1 %>"
Again, I'm new to this. I found this only while trying to search for ways to solve my own problems.
If this is wrong (possible), someone just let me know what I did wrong and I'll delete it.
Related
I have a asp.net gridview that is giving me fits. I'm pulling the data into the grid with no issues. However, when I click edit, I get this error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'wrkCode'.
My intention is to allow the user to edit a group's work schedule using a dropdown list. Here is my code:
<asp:GridView ID="grdShowGroups" runat="server" datakeynames="grpID" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="5" GridLines="Vertical" CellSpacing="5" Width="700px" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="grdShowGroups_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="Edit" />
<asp:BoundField DataField="grpID" HeaderText="grpID" SortExpression="grpID" InsertVisible="False" ReadOnly="True" Visible="false" />
<asp:BoundField DataField="grpStartTime" HeaderText="Start Time" SortExpression="grpStartTime" />
<asp:BoundField DataField="grpEndTime" HeaderText="End Time" SortExpression="grpEndTime" />
<asp:TemplateField HeaderText="Work Schedule" SortExpression="wrkSchedule">
<EditItemTemplate>
<asp:DropDownList ID="drpWrkSchedule" runat="server" DataSourceID="SqlDataSource2" DataTextField="wrkDescription" DataValueField="wrkCode" SelectedValue='<%#Bind("wrkCode")%>' AppendDataBoundItems="true" AutoPostBack="true"></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblWrkSchedule" runat="server" Text='<%# Bind("wrkSchedule") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="grpDescription" HeaderText="Description" SortExpression="grpDescription" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeMGTConnectionString %>" SelectCommand="SELECT [grpID], [grpStartTime], [grpEndTime], [wrkSchedule], [grpDescription] FROM [empGroups]" DeleteCommand="DELETE FROM [empGroups] WHERE [grpID] = #grpID" InsertCommand="INSERT INTO [empGroups] ([grpStartTime], [grpEndTime], [wrkSchedule], [grpDescription]) VALUES (#grpStartTime, #grpEndTime, #wrkSchedule, #grpDescription)" UpdateCommand="UPDATE [empGroups] SET [grpStartTime] = #grpStartTime, [grpEndTime] = #grpEndTime, [wrkSchedule] = #wrkSchedule, [grpDescription] = #grpDescription WHERE [grpID] = #grpID">
<DeleteParameters>
<asp:Parameter Name="grpID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter DbType="DateTime" Name="grpStartTime" />
<asp:Parameter DbType="DateTime" Name="grpEndTime" />
<asp:Parameter Name="wrkSchedule" Type="String" />
<asp:Parameter Name="grpDescription" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter DbType="DateTime" Name="grpStartTime" />
<asp:Parameter DbType="DateTime" Name="grpEndTime" />
<asp:Parameter Name="wrkSchedule" Type="String" />
<asp:Parameter Name="grpDescription" Type="String" />
<asp:Parameter Name="grpID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeMGTConnectionString %>" SelectCommand="SELECT [wrkCode], [wrkDescription], [wrkID] FROM [wrkSchedule]"></asp:SqlDataSource>
If I run it with this code for the dropdown list:
<asp:DropDownList ID="drpWrkSchedule" runat="server" DataSourceID="SqlDataSource2" DataTextField="wrkDescription" DataValueField="wrkCode" SelectedValue='<%#Bind("wrkCode")%>'>
I get the error. IF I run it without the "SelectedValue='<%#Bind("wrkCode")%>'" code, it presents the dropdown list as I need, just without a selected value that connects to the data from the data currently in the table.
I've looked at several examples from all over the web and it may be that I'm just missing something small. I just can't figure this out.
Thanks!
You need to select the wrkCode in your sqldatasource1 otherwise it has nothing to bind to. So just include wrkCode in your select clause of that sql statement and you should be good to go.
I have a problem about the updating a column of my gridview; when I try to update the field I get this error:
Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "#pid".
Here is a piece of my code:
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe rozane" HeaderText="hoghoghe rozane"
SortExpression="hoghoghe rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
<asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
chek this out : same problem
it says you must change [hoghoghe rozane] into [hoghoghe_rozane]
Update :::
1.Make sure that the type of pid field in database
2.fields should not have spaces in your tables
3.alias should not have spaces too
try this code :
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe_rozane" HeaderText="hoghogheRozane"
SortExpression="hoghoghe_rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
hope that would work.
I use all data BoundField in DetailsView from SQL Server. I get the correct display, then I click Edit, then edit some dropdownlist with SQLDataSource and some textboxes. Then I click Update, nothing happen, still same old value and no error. Anyone know why it doesn't work? Here my code,
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="DatabaseName,ServerName,Instance" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" ShowInsertButton="True" />
<asp:BoundField DataField="DatabaseName" HeaderText="DatabaseName" ReadOnly="True" SortExpression="DatabaseName" />
<asp:TemplateField HeaderText="ServerName" SortExpression="ServerName">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ServerName") %>'></asp:Label>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ServerName") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ServerName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WorkProcess" SortExpression="WorkProcess">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="workprocess" DataTextField="WorkProcess" DataValueField="WorkProcess">
</asp:DropDownList>
<asp:SqlDataSource ID="workprocess" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [WorkProcess] FROM [tblWorkProcess]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList8" runat="server" DataSourceID="workprocess" DataTextField="WorkProcess" DataValueField="WorkProcess">
</asp:DropDownList>
<asp:SqlDataSource ID="workprocess" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [WorkProcess] FROM [tblWorkProcess]"></asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("WorkProcess") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Primary_DBA" SortExpression="Primary_DBA">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="userid" DataTextField="UserID" DataValueField="UserID">
</asp:DropDownList>
<asp:SqlDataSource ID="userid" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [UserID] FROM [tblDBA]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList9" runat="server" DataSourceID="userid" DataTextField="UserID" DataValueField="UserID">
</asp:DropDownList>
<asp:SqlDataSource ID="userid" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [UserID] FROM [tblDBA]"></asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Primary_DBA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TMLASGroupNumber" SortExpression="TMLASGroupNumber">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="TMLAS" DataTextField="TMLASGroupNumber" DataValueField="TMLASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="TMLAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [TMLASGroupNumber] FROM [tblTM_LAS]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList10" runat="server" DataSourceID="TMLAS" DataTextField="TMLASGroupNumber" DataValueField="TMLASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="TMLAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [TMLASGroupNumber] FROM [tblTM_LAS]"></asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("TMLASGroupNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TMASGroupNumber" SortExpression="TMASGroupNumber">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="TMAS" DataTextField="TMASGroupNumber" DataValueField="TMASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="TMAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [TMASGroupNumber] FROM [tblTM_AS]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList11" runat="server" DataSourceID="TMAS" DataTextField="TMASGroupNumber" DataValueField="TMASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="TMAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [TMASGroupNumber] FROM [tblTM_AS]"></asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("TMASGroupNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IIASGroupNumber" SortExpression="IIASGroupNumber">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="IIAS" DataTextField="IIASGroupNumber" DataValueField="IIASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="IIAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [IIASGroupNumber] FROM [tblII_AS]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList12" runat="server" DataSourceID="IIAS" DataTextField="IIASGroupNumber" DataValueField="IIASGroupNumber">
</asp:DropDownList>
<asp:SqlDataSource ID="IIAS" runat="server" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" SelectCommand="SELECT [IIASGroupNumber] FROM [tblII_AS]"></asp:SqlDataSource>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("IIASGroupNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Architecture" SortExpression="Architecture">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server">
<asp:ListItem>BSN EAP</asp:ListItem>
<asp:ListItem>BSN NEA</asp:ListItem>
<asp:ListItem>BSNConnect.com</asp:ListItem>
<asp:ListItem>BSNDMZ.COM</asp:ListItem>
<asp:ListItem>Dow EAP</asp:ListItem>
<asp:ListItem>Dow NEA</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList13" runat="server">
<asp:ListItem>BSN EAP</asp:ListItem>
<asp:ListItem>BSN NEA</asp:ListItem>
<asp:ListItem>BSNConnect.com</asp:ListItem>
<asp:ListItem>BSNDMZ.COM</asp:ListItem>
<asp:ListItem>Dow EAP</asp:ListItem>
<asp:ListItem>Dow NEA</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Architecture") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Version" SortExpression="Version">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList7" runat="server">
<asp:ListItem>Oracle 11g</asp:ListItem>
<asp:ListItem>Oracle 11g R2</asp:ListItem>
<asp:ListItem>SQL Server 2008</asp:ListItem>
<asp:ListItem>SQL Server 2008 R2</asp:ListItem>
<asp:ListItem>SQL Server 2012</asp:ListItem>
<asp:ListItem>SQL Svr 2008 R2 SS%S</asp:ListItem>
<asp:ListItem>SQL Svr 2012 SS%S</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList14" runat="server">
<asp:ListItem>Oracle 11g</asp:ListItem>
<asp:ListItem>Oracle 11g R2</asp:ListItem>
<asp:ListItem>SQL Server 2008</asp:ListItem>
<asp:ListItem>SQL Server 2008 R2</asp:ListItem>
<asp:ListItem>SQL Server 2012</asp:ListItem>
<asp:ListItem>SQL Svr 2008 R2 SS%S</asp:ListItem>
<asp:ListItem>SQL Svr 2012 SS%S</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Version") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Quarter_Close_Vital" HeaderText="Quarter_Close_Vital" SortExpression="Quarter_Close_Vital" />
<asp:BoundField DataField="Business_Importance" HeaderText="Business_Importance" SortExpression="Business_Importance" />
<asp:BoundField DataField="Application_Number" HeaderText="Application_Number" SortExpression="Application_Number" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Role_Based_Security_Doc" HeaderText="Role_Based_Security_Doc" SortExpression="Role_Based_Security_Doc" />
<asp:BoundField DataField="Max_Users" HeaderText="Max_Users" SortExpression="Max_Users" />
<asp:BoundField DataField="Storage_Requirements" HeaderText="Storage_Requirements" SortExpression="Storage_Requirements" />
<asp:BoundField DataField="Projected_Growth" HeaderText="Projected_Growth" SortExpression="Projected_Growth" />
<asp:BoundField DataField="Data_Owner_1" HeaderText="Data_Owner_1" SortExpression="Data_Owner_1" />
<asp:BoundField DataField="Data_Owner_2" HeaderText="Data_Owner_2" SortExpression="Data_Owner_2" />
<asp:BoundField DataField="SID" HeaderText="SID" SortExpression="SID" />
<asp:BoundField DataField="Alias" HeaderText="Alias" SortExpression="Alias" />
<asp:BoundField DataField="Instance" HeaderText="Instance" ReadOnly="True" SortExpression="Instance" />
<asp:BoundField DataField="Backup_Nodes" HeaderText="Backup_Nodes" SortExpression="Backup_Nodes" />
<asp:BoundField DataField="Portfolio_Lookup" HeaderText="Portfolio_Lookup" SortExpression="Portfolio_Lookup" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:BoundField DataField="ConnectionString" HeaderText="ConnectionString" SortExpression="ConnectionString" />
<asp:BoundField DataField="InstanceOccurence" HeaderText="InstanceOccurence" SortExpression="InstanceOccurence" />
<asp:BoundField DataField="OccurenceNormalState" HeaderText="OccurenceNormalState" SortExpression="OccurenceNormalState" />
<asp:BoundField DataField="SupportedFuntionalArea" HeaderText="SupportedFuntionalArea" SortExpression="SupportedFuntionalArea" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:Database_Shared_NotebookConnectionString %>" DeleteCommand="DELETE FROM [tblDatabase] WHERE [DatabaseName] = #original_DatabaseName AND [ServerName] = #original_ServerName AND [Instance] = #original_Instance AND [WorkProcess] = #original_WorkProcess AND [Primary_DBA] = #original_Primary_DBA AND [TMLASGroupNumber] = #original_TMLASGroupNumber AND [TMASGroupNumber] = #original_TMASGroupNumber AND [IIASGroupNumber] = #original_IIASGroupNumber AND (([Architecture] = #original_Architecture) OR ([Architecture] IS NULL AND #original_Architecture IS NULL)) AND (([Version] = #original_Version) OR ([Version] IS NULL AND #original_Version IS NULL)) AND (([Quarter_Close_Vital] = #original_Quarter_Close_Vital) OR ([Quarter_Close_Vital] IS NULL AND #original_Quarter_Close_Vital IS NULL)) AND (([Business_Importance] = #original_Business_Importance) OR ([Business_Importance] IS NULL AND #original_Business_Importance IS NULL)) AND (([Application_Number] = #original_Application_Number) OR ([Application_Number] IS NULL AND #original_Application_Number IS NULL)) AND (([Description] = #original_Description) OR ([Description] IS NULL AND #original_Description IS NULL)) AND (([Role_Based_Security_Doc] = #original_Role_Based_Security_Doc) OR ([Role_Based_Security_Doc] IS NULL AND #original_Role_Based_Security_Doc IS NULL)) AND (([Max_Users] = #original_Max_Users) OR ([Max_Users] IS NULL AND #original_Max_Users IS NULL)) AND (([Storage_Requirements] = #original_Storage_Requirements) OR ([Storage_Requirements] IS NULL AND #original_Storage_Requirements IS NULL)) AND (([Projected_Growth] = #original_Projected_Growth) OR ([Projected_Growth] IS NULL AND #original_Projected_Growth IS NULL)) AND (([Data_Owner_1] = #original_Data_Owner_1) OR ([Data_Owner_1] IS NULL AND #original_Data_Owner_1 IS NULL)) AND (([Data_Owner_2] = #original_Data_Owner_2) OR ([Data_Owner_2] IS NULL AND #original_Data_Owner_2 IS NULL)) AND (([SID] = #original_SID) OR ([SID] IS NULL AND #original_SID IS NULL)) AND (([Alias] = #original_Alias) OR ([Alias] IS NULL AND #original_Alias IS NULL)) AND (([Backup_Nodes] = #original_Backup_Nodes) OR ([Backup_Nodes] IS NULL AND #original_Backup_Nodes IS NULL)) AND (([Portfolio_Lookup] = #original_Portfolio_Lookup) OR ([Portfolio_Lookup] IS NULL AND #original_Portfolio_Lookup IS NULL)) AND (([Notes] = #original_Notes) OR ([Notes] IS NULL AND #original_Notes IS NULL)) AND (([ConnectionString] = #original_ConnectionString) OR ([ConnectionString] IS NULL AND #original_ConnectionString IS NULL)) AND (([InstanceOccurence] = #original_InstanceOccurence) OR ([InstanceOccurence] IS NULL AND #original_InstanceOccurence IS NULL)) AND (([OccurenceNormalState] = #original_OccurenceNormalState) OR ([OccurenceNormalState] IS NULL AND #original_OccurenceNormalState IS NULL)) AND (([SupportedFuntionalArea] = #original_SupportedFuntionalArea) OR ([SupportedFuntionalArea] IS NULL AND #original_SupportedFuntionalArea IS NULL))" InsertCommand="INSERT INTO [tblDatabase] ([DatabaseName], [ServerName], [WorkProcess], [Primary_DBA], [TMLASGroupNumber], [TMASGroupNumber], [IIASGroupNumber], [Architecture], [Version], [Quarter_Close_Vital], [Business_Importance], [Application_Number], [Description], [Role_Based_Security_Doc], [Max_Users], [Storage_Requirements], [Projected_Growth], [Data_Owner_1], [Data_Owner_2], [SID], [Alias], [Instance], [Backup_Nodes], [Portfolio_Lookup], [Notes], [ConnectionString], [InstanceOccurence], [OccurenceNormalState], [SupportedFuntionalArea]) VALUES (#DatabaseName, #ServerName, #WorkProcess, #Primary_DBA, #TMLASGroupNumber, #TMASGroupNumber, #IIASGroupNumber, #Architecture, #Version, #Quarter_Close_Vital, #Business_Importance, #Application_Number, #Description, #Role_Based_Security_Doc, #Max_Users, #Storage_Requirements, #Projected_Growth, #Data_Owner_1, #Data_Owner_2, #SID, #Alias, #Instance, #Backup_Nodes, #Portfolio_Lookup, #Notes, #ConnectionString, #InstanceOccurence, #OccurenceNormalState, #SupportedFuntionalArea)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [tblDatabase]" UpdateCommand="UPDATE [tblDatabase] SET [WorkProcess] = #WorkProcess, [Primary_DBA] = #Primary_DBA, [TMLASGroupNumber] = #TMLASGroupNumber, [TMASGroupNumber] = #TMASGroupNumber, [IIASGroupNumber] = #IIASGroupNumber, [Architecture] = #Architecture, [Version] = #Version, [Quarter_Close_Vital] = #Quarter_Close_Vital, [Business_Importance] = #Business_Importance, [Application_Number] = #Application_Number, [Description] = #Description, [Role_Based_Security_Doc] = #Role_Based_Security_Doc, [Max_Users] = #Max_Users, [Storage_Requirements] = #Storage_Requirements, [Projected_Growth] = #Projected_Growth, [Data_Owner_1] = #Data_Owner_1, [Data_Owner_2] = #Data_Owner_2, [SID] = #SID, [Alias] = #Alias, [Backup_Nodes] = #Backup_Nodes, [Portfolio_Lookup] = #Portfolio_Lookup, [Notes] = #Notes, [ConnectionString] = #ConnectionString, [InstanceOccurence] = #InstanceOccurence, [OccurenceNormalState] = #OccurenceNormalState, [SupportedFuntionalArea] = #SupportedFuntionalArea WHERE [DatabaseName] = #original_DatabaseName AND [ServerName] = #original_ServerName AND [Instance] = #original_Instance AND [WorkProcess] = #original_WorkProcess AND [Primary_DBA] = #original_Primary_DBA AND [TMLASGroupNumber] = #original_TMLASGroupNumber AND [TMASGroupNumber] = #original_TMASGroupNumber AND [IIASGroupNumber] = #original_IIASGroupNumber AND (([Architecture] = #original_Architecture) OR ([Architecture] IS NULL AND #original_Architecture IS NULL)) AND (([Version] = #original_Version) OR ([Version] IS NULL AND #original_Version IS NULL)) AND (([Quarter_Close_Vital] = #original_Quarter_Close_Vital) OR ([Quarter_Close_Vital] IS NULL AND #original_Quarter_Close_Vital IS NULL)) AND (([Business_Importance] = #original_Business_Importance) OR ([Business_Importance] IS NULL AND #original_Business_Importance IS NULL)) AND (([Application_Number] = #original_Application_Number) OR ([Application_Number] IS NULL AND #original_Application_Number IS NULL)) AND (([Description] = #original_Description) OR ([Description] IS NULL AND #original_Description IS NULL)) AND (([Role_Based_Security_Doc] = #original_Role_Based_Security_Doc) OR ([Role_Based_Security_Doc] IS NULL AND #original_Role_Based_Security_Doc IS NULL)) AND (([Max_Users] = #original_Max_Users) OR ([Max_Users] IS NULL AND #original_Max_Users IS NULL)) AND (([Storage_Requirements] = #original_Storage_Requirements) OR ([Storage_Requirements] IS NULL AND #original_Storage_Requirements IS NULL)) AND (([Projected_Growth] = #original_Projected_Growth) OR ([Projected_Growth] IS NULL AND #original_Projected_Growth IS NULL)) AND (([Data_Owner_1] = #original_Data_Owner_1) OR ([Data_Owner_1] IS NULL AND #original_Data_Owner_1 IS NULL)) AND (([Data_Owner_2] = #original_Data_Owner_2) OR ([Data_Owner_2] IS NULL AND #original_Data_Owner_2 IS NULL)) AND (([SID] = #original_SID) OR ([SID] IS NULL AND #original_SID IS NULL)) AND (([Alias] = #original_Alias) OR ([Alias] IS NULL AND #original_Alias IS NULL)) AND (([Backup_Nodes] = #original_Backup_Nodes) OR ([Backup_Nodes] IS NULL AND #original_Backup_Nodes IS NULL)) AND (([Portfolio_Lookup] = #original_Portfolio_Lookup) OR ([Portfolio_Lookup] IS NULL AND #original_Portfolio_Lookup IS NULL)) AND (([Notes] = #original_Notes) OR ([Notes] IS NULL AND #original_Notes IS NULL)) AND (([ConnectionString] = #original_ConnectionString) OR ([ConnectionString] IS NULL AND #original_ConnectionString IS NULL)) AND (([InstanceOccurence] = #original_InstanceOccurence) OR ([InstanceOccurence] IS NULL AND #original_InstanceOccurence IS NULL)) AND (([OccurenceNormalState] = #original_OccurenceNormalState) OR ([OccurenceNormalState] IS NULL AND #original_OccurenceNormalState IS NULL)) AND (([SupportedFuntionalArea] = #original_SupportedFuntionalArea) OR ([SupportedFuntionalArea] IS NULL AND #original_SupportedFuntionalArea IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_DatabaseName" Type="String" />
<asp:Parameter Name="original_ServerName" Type="String" />
<asp:Parameter Name="original_Instance" Type="String" />
<asp:Parameter Name="original_WorkProcess" Type="String" />
<asp:Parameter Name="original_Primary_DBA" Type="String" />
<asp:Parameter Name="original_TMLASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_TMASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_IIASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_Architecture" Type="String" />
<asp:Parameter Name="original_Version" Type="String" />
<asp:Parameter Name="original_Quarter_Close_Vital" Type="String" />
<asp:Parameter Name="original_Business_Importance" Type="String" />
<asp:Parameter Name="original_Application_Number" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Role_Based_Security_Doc" Type="String" />
<asp:Parameter Name="original_Max_Users" Type="String" />
<asp:Parameter Name="original_Storage_Requirements" Type="String" />
<asp:Parameter Name="original_Projected_Growth" Type="String" />
<asp:Parameter Name="original_Data_Owner_1" Type="String" />
<asp:Parameter Name="original_Data_Owner_2" Type="String" />
<asp:Parameter Name="original_SID" Type="String" />
<asp:Parameter Name="original_Alias" Type="String" />
<asp:Parameter Name="original_Backup_Nodes" Type="String" />
<asp:Parameter Name="original_Portfolio_Lookup" Type="String" />
<asp:Parameter Name="original_Notes" Type="String" />
<asp:Parameter Name="original_ConnectionString" Type="String" />
<asp:Parameter Name="original_InstanceOccurence" Type="Decimal" />
<asp:Parameter Name="original_OccurenceNormalState" Type="String" />
<asp:Parameter Name="original_SupportedFuntionalArea" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="WorkProcess" Type="String" />
<asp:Parameter Name="Primary_DBA" Type="String" />
<asp:Parameter Name="TMLASGroupNumber" Type="Int32" />
<asp:Parameter Name="TMASGroupNumber" Type="Int32" />
<asp:Parameter Name="IIASGroupNumber" Type="Int32" />
<asp:Parameter Name="Architecture" Type="String" />
<asp:Parameter Name="Version" Type="String" />
<asp:Parameter Name="Quarter_Close_Vital" Type="String" />
<asp:Parameter Name="Business_Importance" Type="String" />
<asp:Parameter Name="Application_Number" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Role_Based_Security_Doc" Type="String" />
<asp:Parameter Name="Max_Users" Type="String" />
<asp:Parameter Name="Storage_Requirements" Type="String" />
<asp:Parameter Name="Projected_Growth" Type="String" />
<asp:Parameter Name="Data_Owner_1" Type="String" />
<asp:Parameter Name="Data_Owner_2" Type="String" />
<asp:Parameter Name="SID" Type="String" />
<asp:Parameter Name="Alias" Type="String" />
<asp:Parameter Name="Backup_Nodes" Type="String" />
<asp:Parameter Name="Portfolio_Lookup" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="ConnectionString" Type="String" />
<asp:Parameter Name="InstanceOccurence" Type="Decimal" />
<asp:Parameter Name="OccurenceNormalState" Type="String" />
<asp:Parameter Name="SupportedFuntionalArea" Type="String" />
<asp:Parameter Name="original_DatabaseName" Type="String" />
<asp:Parameter Name="original_ServerName" Type="String" />
<asp:Parameter Name="original_Instance" Type="String" />
<asp:Parameter Name="original_WorkProcess" Type="String" />
<asp:Parameter Name="original_Primary_DBA" Type="String" />
<asp:Parameter Name="original_TMLASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_TMASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_IIASGroupNumber" Type="Int32" />
<asp:Parameter Name="original_Architecture" Type="String" />
<asp:Parameter Name="original_Version" Type="String" />
<asp:Parameter Name="original_Quarter_Close_Vital" Type="String" />
<asp:Parameter Name="original_Business_Importance" Type="String" />
<asp:Parameter Name="original_Application_Number" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Role_Based_Security_Doc" Type="String" />
<asp:Parameter Name="original_Max_Users" Type="String" />
<asp:Parameter Name="original_Storage_Requirements" Type="String" />
<asp:Parameter Name="original_Projected_Growth" Type="String" />
<asp:Parameter Name="original_Data_Owner_1" Type="String" />
<asp:Parameter Name="original_Data_Owner_2" Type="String" />
<asp:Parameter Name="original_SID" Type="String" />
<asp:Parameter Name="original_Alias" Type="String" />
<asp:Parameter Name="original_Backup_Nodes" Type="String" />
<asp:Parameter Name="original_Portfolio_Lookup" Type="String" />
<asp:Parameter Name="original_Notes" Type="String" />
<asp:Parameter Name="original_ConnectionString" Type="String" />
<asp:Parameter Name="original_InstanceOccurence" Type="Decimal" />
<asp:Parameter Name="original_OccurenceNormalState" Type="String" />
<asp:Parameter Name="original_SupportedFuntionalArea" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
I found out why it doesn't work.
When I replace textbox to dropdownlist, It wipes the databinding. I have to go to Edit DataBinding to set it target to specific column.
Before, it left it blank that is why it does not change anything.
Came across this question while searching for a solution for the same issue. The fix for me was to set the DataKeyNames property of the DetailsView to the primary key for the table.
Please forgive my ignorance. I have a done a bit of web programming but am new to ASP.NET and find it mystifying when trying to do something not out of the box.
I have a GridView that gets its data from a SQL Server view. I have a DetailsView that needs to manipulate data in a table. I cannot figure out how to link the GridView to the DetailsView correctly.
Below is the code for the section of the aspx page that contains the GridView and DetailsView. The latest error in an endless procession of errors is: Must declare the scalar variable "#ID".
I would appreciate any help that anyone can offer. Thanks.
<asp:GridView ID="gvVendorContacts" runat="server" AutoGenerateColumns="False"
DataSourceID="dsApplications_Contacts" AllowSorting="True" CellPadding="4" CellSpacing="2" AutoGenerateSelectButton="True" DataKeyNames="ContactID"
onselectedindexchanged="gvVendorContacts_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#E8F3FF" />
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="Office Phone" HeaderText="Office Phone"
SortExpression="Office Phone" />
<asp:BoundField DataField="Mobile Phone" HeaderText="Mobile Phone"
SortExpression="Mobile Phone" />
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<%#Eval("Email")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsApplications_Contacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
SelectCommand="SELECT [ApplicationID], [ContactID], [FName], [LName], [FullName], [Title], [Role], [OfficePhone] As [Office Phone], [MobilePhone] As [Mobile Phone], [Email] FROM [vw_Applications_Contacts] WHERE ApplicationName = 'Bloomberg'">
</asp:SqlDataSource>
<asp:DetailsView ID="dvVendorContacts" runat="server" AutoGenerateRows="False"
DataKeyNames="ID" DataSourceID="dsVendorContacts" Height="100px"
Width="200px" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4">
<EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<Fields>
<asp:BoundField DataField="ContactID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" />
<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="OfficePhone" HeaderText="OfficePhone"
SortExpression="OfficePhone" />
<asp:BoundField DataField="MobilePhone" HeaderText="MobilePhone"
SortExpression="MobilePhone" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Fields>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
</asp:DetailsView>
<asp:SqlDataSource ID="dsVendorContacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
DeleteCommand="DELETE FROM [Contacts] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Contacts] ([FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email]) VALUES (#FName, #LName, #Title, #Role, #OfficePhone, #MobilePhone, #Email)"
SelectCommand="SELECT [ID], [FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email] FROM [Contacts] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Contacts] SET [FName] = #FName, [LName] = #LName, [Title] = #Title, [Role] = #Role, [OfficePhone] = #OfficePhone, [MobilePhone] = #MobilePhone, [Email] = #Email WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvVendorContacts" DefaultValue="NULL"
Name="ContactID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Looks like your select statement is expecting #ID but your SelectParameter is ContactId.
I have grid view with folowing complete code With Msaccess DB.I have used the decode function in sql query.When i press the edit button on grid view it shows folowing error
"DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
My SQL Data source code is below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString2 %>"
DeleteCommand="DELETE FROM [EMAILS] WHERE [ID] = ?" InsertCommand="INSERT INTO [EMAILS] ([Email], [FULLNAME],[FLAG]) VALUES (?, ?, ?)"
ProviderName="<%$ ConnectionStrings:DataConnectionString2.ProviderName %>" SelectCommand="SELECT ID, Email, FULLNAME, switch(FLAG = 1, 'Allowed', Flag = 0, 'Not Allowed') AS FLAG FROM EMAILS"
UpdateCommand="UPDATE [EMAILS] SET [Email] = ?, [FULLNAME] = ?,[FLAG] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
And Grid View Code is bellow
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="821px" EmptyDataText="No Emails Found">
<RowStyle BackColor="White" Font-Names="Arial" Font-Size="Small" ForeColor="Black" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="FULLNAME" HeaderText="Full Name" SortExpression="FULLNAME" />
<asp:TemplateField HeaderText="Flag" SortExpression="FLAG">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue="<%# Bind('FLAG') %>" AppendDataBoundItems="True">
<asp:ListItem Value="1">Allowed</asp:ListItem>
<asp:ListItem Value="0">Not Allowed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FLAG") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
ForeColor="#FFFFCC" HorizontalAlign="Center" />
<EmptyDataRowStyle BackColor="#804000" Font-Names="Arial" Font-Size="Small" ForeColor="White" />
</asp:GridView>
Please tell me what possible error is here
Check weather the value in Field flag of the row you are trying to edit, is available in the DropDownList in EditItemTemplate
And try removing AppendDataBoundItems="True" in DropDownList in EditItemTemplate