S
siera_gld
Guest
I am trying to use a gridview for companies, edit the entries based on a list coming from a table in SQL Server.
in this example, I have a gridview interfacing a company table. I want the user to be able to select a service area from a uniform list (sql server again) and have those values update the EntityID in the Company Table.
If I use a simple text box which is the default when you add the editing functionality - it binds without any problem. When I change it to the dropdown list, it does not seem to bind.
I'm kind of new to asp pages so forgive the elementary nature of the question.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewEditCompany.aspx.cs" Inherits="Enterprise.ViewEditCompany" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="EntityID" DataSourceID="dsCompany">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="EntityID" HeaderText="EntityID" InsertVisible="False" ReadOnly="True" SortExpression="EntityID" />
<asp:BoundField DataField="CompanyNumber" HeaderText="CompanyNumber" SortExpression="CompanyNumber" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="CompanyAbbreviation" HeaderText="CompanyAbbreviation" SortExpression="CompanyAbbreviation" />
<asp:TemplateField HeaderText="ServiceArea" SortExpression="ServiceArea">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" AutoPostBack="False" DataSourceID="sqlSvcArea" DataTextField="ServiceArea" DataValueField="ServiceArea">
</aspropDownList>
<asp:SqlDataSource ID="sqlSvcArea" runat="server" ConnectionString="<%$ ConnectionStrings:dbPhysEnt %>" ProviderName="<%$ ConnectionStrings:dbPhysEnt.ProviderName %>" SelectCommand="SELECT DISTINCT [ServiceArea] FROM [T_SERVICE_AREA]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ServiceArea") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SA_Mnemonic" HeaderText="SA_Mnemonic" SortExpression="SA_Mnemonic" />
<asp:BoundField DataField="INSRT_DTS" HeaderText="INSRT_DTS" SortExpression="INSRT_DTS" />
<asp:BoundField DataField="INSRT_USR" HeaderText="INSRT_USR" SortExpression="INSRT_USR" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsCompany" runat="server" ConnectionString="<%$ ConnectionStrings:dbPhysEnt %>"
DeleteCommand="DELETE FROM [PE_Entity] WHERE [EntityID] = @EntityID"
InsertCommand="INSERT INTO [PE_Entity] ([CompanyNumber], [CompanyName], [CompanyAbbreviation], [ServiceArea], [SA_Mnemonic], [INSRT_DTS], [INSRT_USR]) VALUES (@CompanyNumber, @CompanyName, @CompanyAbbreviation, @ServiceArea, @SA_Mnemonic, @INSRT_DTS, @INSRT_USR)" ProviderName="<%$ ConnectionStrings:dbPhysEnt.ProviderName %>"
SelectCommand="SELECT * FROM [PE_Entity]"
UpdateCommand="UPDATE [PE_Entity] SET [CompanyNumber] = @CompanyNumber, [CompanyName] = @CompanyName, [CompanyAbbreviation] = @CompanyAbbreviation, [ServiceArea] = @ServiceArea, [SA_Mnemonic] = @SA_Mnemonic, [INSRT_DTS] = @INSRT_DTS, [INSRT_USR] = @INSRT_USR WHERE [EntityID] = @EntityID">
<DeleteParameters>
<asparameter Name="EntityID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asparameter Name="CompanyNumber" Type="String" />
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="CompanyAbbreviation" Type="String" />
<asparameter Name="ServiceArea" Type="String" />
<asparameter Name="SA_Mnemonic" Type="String" />
<asparameter Name="INSRT_DTS" Type="DateTime" />
<asparameter Name="INSRT_USR" Type="String" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="CompanyNumber" Type="String" />
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="CompanyAbbreviation" Type="String" />
<asparameter Name="ServiceArea" Type="String" />
<asparameter Name="SA_Mnemonic" Type="String" />
<asparameter Name="INSRT_DTS" Type="DateTime" />
<asparameter Name="INSRT_USR" Type="String" />
<asparameter Name="EntityID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
KDW
Continue reading...
in this example, I have a gridview interfacing a company table. I want the user to be able to select a service area from a uniform list (sql server again) and have those values update the EntityID in the Company Table.
If I use a simple text box which is the default when you add the editing functionality - it binds without any problem. When I change it to the dropdown list, it does not seem to bind.
I'm kind of new to asp pages so forgive the elementary nature of the question.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewEditCompany.aspx.cs" Inherits="Enterprise.ViewEditCompany" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="EntityID" DataSourceID="dsCompany">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="EntityID" HeaderText="EntityID" InsertVisible="False" ReadOnly="True" SortExpression="EntityID" />
<asp:BoundField DataField="CompanyNumber" HeaderText="CompanyNumber" SortExpression="CompanyNumber" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="CompanyAbbreviation" HeaderText="CompanyAbbreviation" SortExpression="CompanyAbbreviation" />
<asp:TemplateField HeaderText="ServiceArea" SortExpression="ServiceArea">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" AutoPostBack="False" DataSourceID="sqlSvcArea" DataTextField="ServiceArea" DataValueField="ServiceArea">
</aspropDownList>
<asp:SqlDataSource ID="sqlSvcArea" runat="server" ConnectionString="<%$ ConnectionStrings:dbPhysEnt %>" ProviderName="<%$ ConnectionStrings:dbPhysEnt.ProviderName %>" SelectCommand="SELECT DISTINCT [ServiceArea] FROM [T_SERVICE_AREA]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ServiceArea") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SA_Mnemonic" HeaderText="SA_Mnemonic" SortExpression="SA_Mnemonic" />
<asp:BoundField DataField="INSRT_DTS" HeaderText="INSRT_DTS" SortExpression="INSRT_DTS" />
<asp:BoundField DataField="INSRT_USR" HeaderText="INSRT_USR" SortExpression="INSRT_USR" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsCompany" runat="server" ConnectionString="<%$ ConnectionStrings:dbPhysEnt %>"
DeleteCommand="DELETE FROM [PE_Entity] WHERE [EntityID] = @EntityID"
InsertCommand="INSERT INTO [PE_Entity] ([CompanyNumber], [CompanyName], [CompanyAbbreviation], [ServiceArea], [SA_Mnemonic], [INSRT_DTS], [INSRT_USR]) VALUES (@CompanyNumber, @CompanyName, @CompanyAbbreviation, @ServiceArea, @SA_Mnemonic, @INSRT_DTS, @INSRT_USR)" ProviderName="<%$ ConnectionStrings:dbPhysEnt.ProviderName %>"
SelectCommand="SELECT * FROM [PE_Entity]"
UpdateCommand="UPDATE [PE_Entity] SET [CompanyNumber] = @CompanyNumber, [CompanyName] = @CompanyName, [CompanyAbbreviation] = @CompanyAbbreviation, [ServiceArea] = @ServiceArea, [SA_Mnemonic] = @SA_Mnemonic, [INSRT_DTS] = @INSRT_DTS, [INSRT_USR] = @INSRT_USR WHERE [EntityID] = @EntityID">
<DeleteParameters>
<asparameter Name="EntityID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asparameter Name="CompanyNumber" Type="String" />
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="CompanyAbbreviation" Type="String" />
<asparameter Name="ServiceArea" Type="String" />
<asparameter Name="SA_Mnemonic" Type="String" />
<asparameter Name="INSRT_DTS" Type="DateTime" />
<asparameter Name="INSRT_USR" Type="String" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="CompanyNumber" Type="String" />
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="CompanyAbbreviation" Type="String" />
<asparameter Name="ServiceArea" Type="String" />
<asparameter Name="SA_Mnemonic" Type="String" />
<asparameter Name="INSRT_DTS" Type="DateTime" />
<asparameter Name="INSRT_USR" Type="String" />
<asparameter Name="EntityID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
KDW
Continue reading...