Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将asp.net表单视图从另一页更改为插入模式_C#_Html_Asp.net_Visual Studio_Webforms - Fatal编程技术网

C# 将asp.net表单视图从另一页更改为插入模式

C# 将asp.net表单视图从另一页更改为插入模式,c#,html,asp.net,visual-studio,webforms,C#,Html,Asp.net,Visual Studio,Webforms,我有两个ASP.NET网页是用ASP.NET Web From编写的。 在第1页,我有主网格视图控件。 在第2页,我在一个From View控件中列出了详细信息 我在第一页有一个按钮。单击按钮。我想换个房间 从视图模式到插入。有什么办法我能做到吗 我的代码如下: 第1页:ASPX页:按钮和网格视图 <asp:Panel ID="pnl" runat="server"> <table> <tr>

我有两个ASP.NET网页是用ASP.NET Web From编写的。 在第1页,我有主网格视图控件。 在第2页,我在一个From View控件中列出了详细信息

我在第一页有一个按钮。单击按钮。我想换个房间 从视图模式到插入。有什么办法我能做到吗

我的代码如下:

第1页:ASPX页:按钮和网格视图

<asp:Panel ID="pnl" runat="server">
        <table>
            <tr>
                <td>
                    <asp:Button ID="btnNewIssue" Text="Create New Issue" runat="server" OnClick="btnNewIssue_Click" />
                </td>
            </tr>
</table>
</asp:Panel>
 <asp:Panel>
    <asp:GridView ID="gvTasks" runat ="server">
Grid View Code--------------------------------
</asp:GridView>
</asp:Panel>
第2页:aspx表单视图

<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
---Item Template Code....
</ItemTemplate>
<EditItemTemplate>
--- Edit Item Template Code....
</EditItemTemplate>
<InsertItemTemplate>
--- Insert Item Template Code....
</InsertItemTemplate>
</asp:FormView>

更改
FillFormView
函数

private void FillFormView()
    {

       var taskId = Request.QueryString["TaskID"];

       if (taskId == null){
           FormView1.ChangeMode(FormViewMode.Insert);
           return;
       }

       FormView1.ChangeMode(FormViewMode.Edit);
       /// dlist from Service based on taskid-----
       FormView1.DataSource = dlist;
        FormView1.DataBind();
}
formview 1\u ModeChanging
功能没有ned

还有一件事,使用string.Format代替StringBuilder类

protected void gvTasks_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            Response.Redirect(string.Format("~/Details.aspx?TaskID={0}", index));
            //Response.Redirect("~/Details.aspx?TaskID=1234");

        }

}
或者您可以使用锚定标记而不是按钮

<a href="Details.aspx">Create New Issue</a>
protected void gvTasks_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            Response.Redirect(string.Format("~/Details.aspx?TaskID={0}", index));
            //Response.Redirect("~/Details.aspx?TaskID=1234");

        }

}
protected void btnNewIssue_Click(object sender, EventArgs e)
{
     Response.Redirect("~/Details.aspx");
}
<a href="Details.aspx">Create New Issue</a>
private void FillFormView()
{
   if (string.IsNullOrEmpty(Request.QueryString["TaskID"])){
       FormView1.ChangeMode(FormViewMode.Insert);
   }
   else
   {
       int taskid = int.Parse(Request.QueryString["TaskID"]);
       FormView1.ChangeMode(FormViewMode.Edit);
       ----- Fetch dlist from Service based on taskid-----
       FormView1.DataSource = dlist;
       FormView1.DataBind();
   }
}