I'm trying to edit a column of a table after I search it using a drop down list; however, when I click the "Edit" button nothing shows up. Please advise and thank you!
More info: I have a Home page where the drop down list is located and as I click search it references the Results.aspx page where the table is shown and, as stated above, when I click edit nothings shows up.
Home.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Inventory
{
public partial class Home : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=10.10.101.188;Initial Catalog=ActioNetITInventory;User ID=rails.sa;Password=ActioNet1234");
protected void Page_Load(object sender, EventArgs e)
{
//methods
Populate1();
}//end page_load
//puts data on the first dropdown list
public void Populate1()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM [Inventory]", new SqlConnection(ConfigurationManager.AppSettings["ConnString"]));
cmd.Connection.Open();
SqlDataReader ddlValues;
ddlValues = cmd.ExecuteReader();
DropDownList1.DataSource = ddlValues;
DropDownList1.DataValueField = "Assigned";
DropDownList1.DataTextField = "Assigned";
DropDownList1.DataBind();
//starts the dropdown list with empty so you can search with serial or the drop down
DropDownList1.Items.Insert(0, new ListItem(String.Empty, "--Select--"));
DropDownList1.SelectedIndex = 0;
cmd.Connection.Close();
cmd.Connection.Dispose();
}//end populate one
}//end class
}//end namespace Inventory
Results.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Inventory
{
public partial class Results : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=10.10.101.188;Initial Catalog=ActioNetITInventory;User ID=rails.sa;Password=ActioNet1234");
protected void Page_Load(object sender, EventArgs e)
{
}
}//end class
}//end name space
Results.html:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Results.aspx.cs" Inherits="Inventory.Results" %>
<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb">
<head id="Head1" runat="server">
<title>Results</title>
<link href="StyleSheet1.css" rel="stylesheet" />
<link href="Background.css" rel="stylesheet" type="text/css" />
<link href="Default.css" rel="stylesheet" />
<link href="Component.css" rel="stylesheet" />
<link rel="shortcut icon" href="~/logo.ico" type="image/x-icon" />
<style type="text/css">
.auto-style1 {
height: 80px;
width: 335px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 400px">
<br />
<br />
<br />
<br />
<br />
<br />
<!--logo-->
<img alt="" class="auto-style1" src="logo.jpg" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
CellPadding="4"
DataKeyNames="Serial"
DataSourceID="SqlDataSource1"
ForeColor="#333333"
ShowFooter="True"
Width="1393px" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="True" ButtonType="Button" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Serial" HeaderText="Serial" ReadOnly="True" SortExpression="Serial" />
<asp:TemplateField HeaderText="Assigned" SortExpression="Assigned">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Assigned") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Assigned") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Location") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Location") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ActioNetITInventoryConnectionString %>"
SelectCommand="SELECT * FROM [Inventory] WHERE ([Assigned] = @Assigned)"
DeleteCommand="DELETE FROM [Inventory] WHERE [Serial] = @Serial"
InsertCommand="INSERT INTO [Inventory] ([Type], [Make], [Model], [Serial], [Assigned], [Location], [Notes]) VALUES (@Type, @Make, @Model, @Serial, @Assigned, @Location, @Notes)"
UpdateCommand="UPDATE [Inventory] SET [Type] = @Type, [Make] = @Make, [Model] = @Model, [Assigned] = @Assigned, [Location] = @Location, [Notes] = @Notes WHERE [Serial] = @Serial">
<DeleteParameters>
<asp:Parameter Name="Serial" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Make" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="Serial" Type="String" />
<asp:Parameter Name="Assigned" Type="String" />
<asp:Parameter Name="Location" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:FormParameter FormField="DropDownList1" Name="Assigned" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Make" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="Assigned" Type="String" />
<asp:Parameter Name="Location" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Serial" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Home.aspx" Text="Back" Width="88px" />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire