在后面的代码中,我从数据库中收集信息,然后循环,在不同的表中显示该信息。我想让网站的用户能够更新每一行的“用户”和“注释”字段。
Environments.aspx 的一部分:
<asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="Panel1"
OnItemDataBound="ListView_ItemDataBound" CellSpacing="2"
CellPadding="2" ShowHeaderWhenEmpty="True">
<LayoutTemplate>
<asp:Panel runat="server" ID="Panel1"></asp:Panel>
</LayoutTemplate>
<ItemTemplate>
<br />
<%#Eval("Name") %> (Database: <%#Eval("Database") %>):
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="180000" ontick="Timer1_Tick">
</asp:Timer>
<asp:GridView ID="GridView1" runat="server" Width="800" CellPadding="2" CellSpacing="2" AutoGenerateColumns="False" >
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="LinkAddress" DataTextField="ServerName" HeaderText="Server:" Target="_blank" ItemStyle-Width="200" />
<%--<asp:BoundField DataField="ServerName" HeaderText="Server:" />--%>
<asp:BoundField DataField="Environment" HeaderText="Environment" ItemStyle-Width="50" />
<asp:BoundField DataField="Users" HeaderText="Users" ItemStyle-Width="50" />
<asp:BoundField DataField="Build" HeaderText="Build" ItemStyle-Width="200" />
<asp:BoundField DataField="Notes" HeaderText="Notes" />
<asp:TemplateField HeaderText="Update" ItemStyle-Width="50">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="EditRow"
Text="Edit" Visible='<%# PrivilegedUser() %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:ListView>
Environments.aspx.cs 的一部分:
protected void Page_Load(object sender, EventArgs e)
{
ListView ListView1;
ListView1 = (ListView)LoginView2.FindControl("ListView1");
if (!IsPostBack)
{
ListView1.DataSource = Envs;
ListView1.DataBind();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
ListView ListView1;
ListView1 = (ListView)LoginView2.FindControl("ListView1");
if (!IsPostBack)
{
ListView1.DataSource = Envs;
ListView1.DataBind();
}
}
protected Boolean PrivilegedUser()
{
SQLConnections SQL = new SQLConnections();
bool IsPrivileged = SQL.IsUserPrivileged();
return IsPrivileged;
}
public class Environment
{
public int EnvId { get; set; }
public string LineBreak { get; set; }
public string Name { get; set; }
public string Database { get; set; }
public List<Svrs> Svrs { get; set; }
}
public class Svrs
{
public int ServerId { get; set; }
public string ServerName { get; set; }
public string Environment { get; set; }
public string Users { get; set; }
public string Build { get; set; }
public string Notes { get; set; }
public string LinkAddress { get; set; }
}
public List<Environment> Envs
{
get
{
string[] EnvList = GetEnvs();
List<string> ServerList = GetServers();
string[,] DBNamesAndServers = GetDBNamesAndServers();
string[] DBServers = GetDataBaseServer(DBNamesAndServers);
string[] DBNames = GetDataBaseName(DBNamesAndServers);
int num = EnvList.Count();
List<Environment> CompleteEnvList = new List<Environment>();
List<Environment> CompleteServerList = new List<Environment>();
List<Environment> CompleteTempList = new List<Environment>();
int i = 0;
int z = 1;
while(i<num)
{
string envname = EnvList[i];
string dbserver = "Unknown";
int index = 0;
if (DBNames.Contains(EnvList[i]))
{
index = Array.IndexOf(DBNames, EnvList[i]);
dbserver = (DBServers[index]);
}
string[,] CurServerInfo = GetSvrs(ServerList, envname);
List<Svrs> NewSvr = new List<Svrs>();
NewSvr.AddRange(NewSvrInfo(CurServerInfo, z));
Environment CurrentSvr = new Environment();
Environment CurrentEnv = new Environment();
CurrentSvr = new Environment
{
EnvId = i+1,
LineBreak = "",
Name = envname,
Database = dbserver,
Svrs = NewSvr,
};
CompleteServerList.Add(CurrentSvr);
CompleteEnvList.AddRange(CompleteServerList);
i++;
z = z + 10;
}
return CompleteServerList; //CompleteEnvList;
}
}
目前,当我点击“编辑”链接时,页面刚刚刷新。我需要能够知道用户正在更新的行的“环境”、“用户”和“注释”的值,这样我才能真正更新数据库并刷新表。任何帮助将不胜感激。