【发布时间】:2014-06-18 19:31:48
【问题描述】:
我有一个 web 应用程序,它调用 SQL 查询以获取受项目影响的应用程序列表。我希望我的管理员能够随意单击编辑并将删除应用程序添加到此列表中。目前,当他们单击编辑时,他们会将受任何项目影响的每个应用程序都视为列表框的一部分,即使在 Gridview 中他们只看到受该特定项目影响的应用程序。当我对项目的值进行硬编码时,它可以工作,但我需要它是一个变量,具体取决于我的管理员单击哪个项目进行编辑。
select
Applications.ApplicationName,
Projects.ProjectName
from ImpactedApplications
inner join Applications
on ImpactedApplications.AppId=Applications.AppId
inner join Projects
on ImpactedApplications.ProjectId=Projects.ProjectId
Where Projects.ProjectId=57 <--This is Hardcoded. I need this to be dynamic.
添加代码
<asp:TemplateField HeaderText="ImpactedApplications">
<EditItemTemplate>
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="ImpactedApps"
DataTextField="ApplicationName" DataValueField="ProjectName" Width="250px"></asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Add" />
<asp:Button ID="Button2" runat="server" Text="Remove" />
<asp:ListBox ID="ListBox3" runat="server" DataSourceID="Applications"
DataTextField="ApplicationName" DataValueField="AppId" Width="250px">
</asp:ListBox>
<br />
<asp:SqlDataSource ID="ImpactedApps" runat="server"
ConnectionString="<%$ ConnectionStrings:LandscapeServicesConnectionString %>"
SelectCommand="select Applications.ApplicationName, Projects.ProjectName
from ImpactedApplications
inner join Applications
on ImpactedApplications.AppId=Applications.AppId
inner join Projects
on ImpactedApplications.ProjectId=Projects.ProjectId
where Projects.ProjectName=@Projectname">
<SelectParameters>
<asp:FormParameter DefaultValue="PO Consolidation (EDW)"
FormField="Gridview1 - Column[2] - Project Name" Name="Project Name" />
</SelectParameters>
</asp:SqlDataSource>
添加背景代码
public partial class Update : System.Web.UI.Page
{
public string query { get; set; }
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LandscapeServicesConnectionString"].ConnectionString);
DataSet dt = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
}
【问题讨论】:
标签: c# sql sql-server-2008