使用Formview

时间:2015-06-11 23:36:29

标签: c# listview formview

我将自己的邮件界面系统添加到我的应用程序中,然后用户点击Repsendbtn到listview,名为“viewmsgView”,然后他将隐藏“viewmsgView”并显示“repmsgform”并根据mailno将数据绑定到repmsgform。我所面对的是你们都知道无法控制到listview或formview,而repsendbtn在formview中,它将依赖于其他控件来处理下面的代码,但我在控件ID下面带有红线的消息:“名称'标签'在当前上下文中不存在”,所以我如何解决这种情况并使按钮代码顺利运行。它可能真的不是很清楚我的帖子,所以我决定制作记录屏幕,我希望能够轻松解释我在寻找什么。请点击以下链接,查看我的屏幕记录,在那里我解释我在寻找的内容:

https://www.youtube.com/watch?v=OMKp7b6iMJ8&feature=youtu.be

<asp:FormView ID="repmsgform" runat="server"  DataKeyNames="mailno" Width="100%" >
                          <ItemTemplate>

                      <div>
                      <table class="table table-bordered" style="margin-left:0px;" >
                     <tbody>
                        <tr>
                            <td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                Ads Number:
                            </td>
                            <td >
                                <asp:Label ID="adsnummsglbl" runat="server" Text='<%# Bind("AdsID") %>' ></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                Message Title:
                            </td>
                            <td>
                                <asp:Label ID="adstitmsglbl" runat="server" Color="#669900" Text='<%# Bind("Mestitle") %>'></asp:Label>
                            </td>
                        </tr>

                        <tr>
                            <td td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">
                                From:&nbsp;&nbsp;
                            </td>
                            <td>
                                <asp:Label ID="Reciverlblnme" runat="server" Text='<%# Bind("Receiver") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>

                            <td style="border-collapse:collapse; border:2px solid white; color:#333333; background-color:#f0f0f0;">To:</td>
                            <td> <asp:Label ID="Tolbl" runat="server" Text='<%# Bind("sender") %>'></asp:Label></td>
                        </tr>

                           </tbody>
                    </table>

                      <div class="form-group">
                          <asp:Label ID="Label12" runat="server" Text="Label" CssClass="col-md-3 control-label">Your Message:</asp:Label>

                                <div class="col-md-9">
                                <asp:TextBox ID="TextBox1" runat="server" Height="150px" TextMode="multiline" CssClass="form-control" 
                                    ></asp:TextBox>
                                    </div>
                                    </div>

                                <asp:Label ID="msgsentlbl" runat="server" Font-Size="Medium" ForeColor="#669900"></asp:Label>

                            <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <div class="pull-right">
                                <asp:Button ID="Closebtn" runat="server" Text="Close" 
                                     CssClass="btn btn-default" onclick="Closebtn_Click"/>
                               &nbsp;&nbsp;&nbsp;&nbsp;
                      <asp:Button runat="server" ID="Repsendbtn" Text="Send" CssClass="btn btn-primary" 
                                    onclick="Repsendbtn_Click"/></div>
                      </div></div>

                   </ItemTemplate>
                          </asp:FormView>







 protected void Repsendbtn_Click(object sender, EventArgs e)
    {

        if (Session["UsrNme"] != null)
        {

            using (SqlConnection cn = new SqlConnection(sc))
            {

                string SendMsgSQL = @"INSERT mails [CVs] ([Message], [Mestitle], [AdsID], [Date], [Receiver], [sender])
        VALUES (@Message, @Mestitle, @AdsID , @Date, @Receiver, @sender)";

                using (SqlCommand SendMsgcmd = new SqlCommand(SendMsgSQL, cn))
                {

                    cn.Open();
                    var user = Session["UsrNme"];

                    SendMsgcmd.Parameters.AddWithValue("@sender", user);
                    SendMsgcmd.Parameters.AddWithValue("@Message", TextBox1.Text);
                    SendMsgcmd.Parameters.AddWithValue("@Mestitle", adstitmsglbl.Text);
                    SendMsgcmd.Parameters.AddWithValue("@AdsID", adsnummsglbl.Text);
                    SendMsgcmd.Parameters.AddWithValue("@Date", DateTime.Now);
                    SendMsgcmd.Parameters.AddWithValue("@Receiver", Reciverlblnme.Text);

                    SendMsgcmd.ExecuteNonQuery();

                    Response.Redirect("User panel.aspx");
                }
            }
        }

        else
        {
            // Consider throwing an error (if these fields are required)
        }

    }

0 个答案:

没有答案
相关问题