使用asp.net c#在点击提交按钮后插入评级

本文关键字:按钮 插入 提交 net asp 使用 | 更新日期: 2023-09-27 18:07:16

我正试图将我的评级表单插入到基于点击提交表单按钮的DB,但我得到以下错误。

编译错误消息:CS0123: No overload for 'sendbtnSubmit' matches delegate 'System。EventHandler '

kgis.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="kgis.aspx.cs" Inherits="portal.kgis" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <!DOCTYPE html>
   <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <style>
    .ratingStar
            {
                font-size: 0pt;
                width: 13px;
                height: 12px;          
                cursor: pointer;
                display: block;
                background-repeat: no-repeat;
            }
            .filledStar
            {
                background-image: url(images/Filled_Star.png);
            }
            .emptyStar
            {
                background-image: url(images/Empty_Star.png);
            }
            .savedStar
            {
                background-image: url(images/Saved_Star.png);
            }
            .auto-style1 {
                height: 50px;
            }
    </style>
    </head>
    <body class="hold-transition skin-blue sidebar-mini">
     <div id="popupContact">
                    <!-- Contact Us Form -->
                    <form action="#" id="feed" method="post" name="form" runat="server">
                        <h2>FeedBack</h2>
                        <hr />
                         <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  </asp:ToolkitScriptManager>


                        <table style="width: 60%;">
                            <tr>
                                <td style="font-weight: bold; padding-top: 1px;">
                                    <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="name" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold; padding-top: 12px;">
                                    <asp:Label ID="Label2" runat="please can anyone help me on this i want to to store the rating to databse after clicking submit (onclick) form..server" Text="E-Mail"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="email" runat="server"></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" forecolor="red" ValidationExpression="'w+([-+.']'w+)*@'w+([-.]'w+)*'.'w+([-.]'w+)*" ControlToValidate="email" ErrorMessage="Input valid email!"></asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold; padding-top: 28px;">
                                    <asp:Label ID="Label3" runat="server" Text="Area"></asp:Label>
                                </td>
                                <td>
                                    <div class="drop1">
                                        <asp:DropDownList runat="server" ID="ddlfields">
                                            <asp:ListItem Value="-1">--Select--</asp:ListItem>
                                            <asp:ListItem Value="gui">GUI</asp:ListItem>
                                            <asp:ListItem Value="coc">Correctness Of Content</asp:ListItem>
                                            <asp:ListItem Value="sug">Suggestions</asp:ListItem>
                                            <asp:ListItem Value="new">New Requirements</asp:ListItem>
                                            <asp:ListItem T Value="efs">Existing Functionality Status</asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold; padding-top: 28px;">
                                    <asp:Label ID="Label6" runat="server" Text="Category"></asp:Label>
                                </td>
                                <td>
                                    <div class="drop">
                                        <asp:DropDownList runat="server" ID="cate">
                                            <asp:ListItem Value="-1">--Select--</asp:ListItem>
                                            <asp:ListItem Value="Hostel">Hostel </asp:ListItem>
                                            <asp:ListItem Value="School">School</asp:ListItem>
                                            <asp:ListItem Value="Backwardclass">Backwardclass</asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold;">
                                    <asp:Label ID="Label4" runat="server" Text="Feedback"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="msg" runat="server" TextMode="MultiLine"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="Label5" runat="server" Text="Rating"></asp:Label>
                                    </td>
                                <td>
                                    <asp:Rating ID="Rating1" runat="server" StarCssClass="ratingStar" WaitingStarCssClass="savedStar"
                                        FilledStarCssClass="filledStar" EmptyStarCssClass="emptyStar" AutoPostBack="true"  MaxRating="5"
                        onchange="Rating1_Changed"                >
                                    </asp:Rating>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <asp:Label ID="lbl_point" runat="server"></asp:Label>
                                </td>
                            </tr>
                        </table>
                        <asp:Button ID="submit" runat="server" OnClick="sendbtnSubmit" Text="Send" />
         </form>
                </div>
    </body>
    </html>

kgis.aspx.cs

    using System.Data.SqlClient;
using AjaxControlToolkit;
  namespace portal
    {
        public partial class kgis : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
            protected void sendbtnSubmit(object sender,AjaxControlToolkit.RatingEventArgs e)
            {
     string connectionString = "Server=KSRSAC-G2G''SQLEXPRESS;Database=Registration;Uid=sa;Pwd=SA#123;";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("INSERT INTO [Registration].[dbo].[FeedBack] (Name,Emailid,Category,Feedback,Area,Rate) VALUES (@Name, @Emailid,@Category,@Feedback,@Area,@Rate)");
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = connection;
                    cmd.Parameters.AddWithValue("@Name", name.Text);
                    cmd.Parameters.AddWithValue("@Emailid", email.Text);
                    cmd.Parameters.AddWithValue("@Category", cate.Text);
                    cmd.Parameters.AddWithValue("@Feedback", msg.Text);
                    cmd.Parameters.AddWithValue("@Area", ddlfields.Text);
                    cmd.Parameters.AddWithValue("@Rate", e.Value.ToString());
                    connection.Open();
                    cmd.ExecuteNonQuery();
         }
    }
    protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
            {
                lbl_point.Text = "You rated " + e.Value.ToString();
            }
        }
    }

我想在使用asp.net c#点击提交表单后将评级存储到数据库。

使用asp.net c#在点击提交按钮后插入评级

按如下方式编写代码:

你没有使用AjaxControlToolkit。RatingEventArgs在你的代码,所以它不清楚从哪里来的。

protected void sendbtnSubmit(object sender,EventArgs e)
            {
     string connectionString = "Server=KSRSAC-G2G''SQLEXPRESS;Database=Registration;Uid=sa;Pwd=SA#123;";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("INSERT INTO [Registration].[dbo].[FeedBack] (Name,Emailid,Category,Feedback,Area,Rate) VALUES (@Name, @Emailid,@Category,@Feedback,@Area,@Rate)");
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = connection;
                    cmd.Parameters.AddWithValue("@Name", name.Text);
                    cmd.Parameters.AddWithValue("@Emailid", email.Text);
                    cmd.Parameters.AddWithValue("@Category", cate.Text);
                    cmd.Parameters.AddWithValue("@Feedback", msg.Text);
                    cmd.Parameters.AddWithValue("@Area", ddlfields.Text);
                    cmd.Parameters.AddWithValue("@Rate", e.Value.ToString());
                    connection.Open();
                    cmd.ExecuteNonQuery();
         }
    }
    protected void Rating1_Changed(object sender, EventArgs e)
            {
                lbl_point.Text = "You rated " + e.Value.ToString();
            }
        }

改变这一行:

protected void sendbtnSubmit(object sender,AjaxControlToolkit.RatingEventArgs e)

:

protected void sendbtnSubmit(object sender,EventArgs e)

编辑:

对于第二个问题,你在评论中说,你有两个选择:

1-在Rating1_Changed事件中处理数据库。(不推荐)

2-在sendbtnSubmit事件,而不是使用e.Value.ToString(),使用这个myabe Rating1.CurrentRating.ToString()