ASP
您好,我正在处理一个用和编写的网页C#
,我可以在其中添加edit and delete
来自database
. 该网页的每一行都grid view
包含 a select, edit and delete links
,并且这些行按日期排序。所以我的问题是:
我怎样才能插入一条新记录,并自动转到相应的页面?(以网格视图页面大小为 5 为例)
这是网格视图的一部分
<asp:GridView ID="grdSchedulerApplications" runat="server" AutoGenerateColumns="False"
Visible="false" ShowFooter="True" PageSize="5" DataKeyNames="sa_ID, sa_ApplicationID"
AllowPaging="True" OnRowCommand="grdSchedulerApplications_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Application" HeaderStyle-HorizontalAlign="Left">
<EditItemTemplate>
<asp:DropDownList ID="ddlEditSchedulerApplications" runat="server" AutoPostBack="True"
DataTextField="app_Name" DataValueField="app_Id">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%# Eval("Application")%>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSchedulerApplications" runat="server" AutoPostBack="True"
DataTextField="app_Name" DataValueField="app_Id">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
然后我有 C# 代码:
protected void grdSchedulerApplications_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Insert"))
{
try
{
int saSchdlrID;
int.TryParse(grdBulkScheduler.SelectedDataKey.Values[0].ToString(), out saSchdlrID);
DropDownList ddlSchedulerApps = (DropDownList)grdSchedulerApplications.FooterRow.FindControl("ddlSchedulerApplications");
int appID;
int.TryParse(ddlSchedulerApps.SelectedValue.ToString(), out appID);
//calling a method from another class to add/update records into database
object obj = cData.AddUpdateBulkSchedulerApplications(0, saSchdlrID, appID);
//query returns the automatically incremented ID of newly created record into obj
if (obj.ToString() != "0")
{
//do some action
//here I need to go to the corresponding page Index
}
}
catch (Exception ex)
{
//exception
}
}