Error with GridView_RowCommand

Last post 06-21-2009 12:08 AM by fallenangel13. 5 replies.

Sort Posts:

  • Error with GridView_RowCommand

    06-20-2009, 2:30 PM
    • Member
      1 point Member
    • fallenangel13
    • Member since 06-20-2009, 2:21 PM
    • Posts 3

     Hi People,

     I encounter this error message of "'ASP.premiumuserpages_ringtones_aspx' does not contain a definition for 'searchRingtonesGridView_RowCommand' and no extension method 'searchRingtonesGridView_RowCommand' accepting a first argument of type 'ASP.premiumuserpages_ringtones_aspx' could be found (are you missing a using directive or an assembly reference?)"

    Have been trying to solve this for some time, anyone willing to help me out here?

    Here's my code:

    Ringtones.aspx

    <%@ Page Language="C#" MasterPageFile="~/global.Master" AutoEventWireup="false" CodeBehind="Ringtones.aspx.cs" Inherits="iMakeTonesWeb.Ringtones" %>

    <asp:Content ID="mainContent" ContentPlaceHolderID="mainContentPlaceHolder" runat="server">


    <h2 style="margin-left: 45px">Download Ringtones</h2>

    <p style="margin-left: 45px">Premium user may download any customised ringtones in the share pools. Per download cost only S$0.99.</p>
    <p style="margin-left: 45px">Search ringtones:
        <asp:TextBox ID="searchRingtonesTextBox" runat="server"></asp:TextBox>
        <asp:Button ID="searchRingtonesButton" runat="server" Text="Search"
            onclick="searchRingtonesButton_Click" /></p>
        <asp:GridView ID="searchRingtonesGridView" runat="server" AutoGenerateColumns="False"
                                OnRowCommand="searchRingtonesGridView_RowCommand" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="ringtoneName" HeaderText="ringtoneName"
                    SortExpression="ringtoneName" />
                <asp:BoundField DataField="UserName" HeaderText="UserName"
                    SortExpression="UserName" />
                <asp:BoundField DataField="uploadDate" HeaderText="uploadDate"
                    SortExpression="uploadDate" />
                <asp:BoundField DataField="ringtonePath" HeaderText="ringtonePath"
                    SortExpression="ringtonePath" />
                <asp:BoundField DataField="genreName" HeaderText="genreName"
                    SortExpression="genreName" />
                <asp:ButtonField ButtonType="Button" CommandName="Download"
                    Text="Download" />
            </Columns>
        </asp:GridView>
        <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:iMakeTonesSiteDatabaseConnectionString %>"

                               
                               
                                SelectCommand="SELECT r.ringtoneName, u.UserName, r.uploadDate, r.ringtonePath, g.genreName FROM RINGTONE AS r INNER JOIN aspnet_Users AS u ON r.userId = u.UserId INNER JOIN GENRE AS g ON r.genreId = g.genreId WHERE (r.ringtoneName LIKE '%' + @SearchStr + '%')">
        <SelectParameters>
            <asp:ControlParameter ControlID="searchRingtonesTextBox"
                Name="SearchStr" PropertyName="Text" DefaultValue="" />
        </SelectParameters>
                            </asp:SqlDataSource>
                            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <table border="0" style="width: 840px">
      <tr>
        <td width="572"><h2 style="margin-left: 45px">Upload Ringtones</h2>
          <p style="margin-left: 45px">Premium users may share their customised ringtones here. Any download by other user, creator may earn $0.39 per download. A credit note will be credited in your user account.</p>
          <form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
            <p style="margin-left:45px">
                Name of Ringtones:
                <asp:TextBox ID="nameOfRingtoneTextBox" runat="server"></asp:TextBox>
                <br />
                Genre:
                <asp:DropDownList ID="DropDownList1" runat="server"
                    DataSourceID="SqlDataSource2" DataTextField="genreName"
                    DataValueField="genreId">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                    ConnectionString="<%$ ConnectionStrings:iMakeTonesSiteDatabaseConnectionString %>"
                    SelectCommand="SELECT [genreName], [genreId] FROM [GENRE]">
                </asp:SqlDataSource>
                <br />
                Select your ringtone to upload:
                <asp:FileUpload ID="ringtoneUpload" runat="server" />
                <br />
                <asp:Label ID="UploadDetails" runat="server" Text="Label" Visible="false"></asp:Label>
                <br />
                <asp:Button ID="uploadRingtoneButton" runat="server" Text="Submit"
                    onclick="uploadRingtoneButton_Click" />
            </p>
          </form>
        <br />
        <br />
        <br />
        <p style="margin-left: 45px">Note : Only support .m4r audio format for sharing. iMakeTones has the rights to remove any unauthorised work which violated iMakeTones regulation and against government law.</p>
        </td>

      </tr>
    </table>
    <p></p>
          <span class="style2">Best viewed with IE 5.5 and above. Disclaimer: Service by iMT Inc Copyright © 2009 iMT! iMakeTones Inc. </span>
        <br class="style2" />
        <span class="style2">All Rights Reserved. Intellectual Property Rights Policy.
        </span>

    </asp:Content>

    Ringtones.aspx.cs

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;


    namespace iMakeTonesWeb
    {
        public partial class Ringtones : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void uploadRingtoneButton_Click(object sender, EventArgs e)
            {
                if (ringtoneUpload.HasFile == false)
                    {
                        // No file uploaded!
                        UploadDetails.Text = "Please first select a file to upload...";
                        UploadDetails.Visible = true;
                    }
                else if (nameOfRingtoneTextBox.Text == "")
                    {
                        UploadDetails.Text = "Please enter a name for the ringtone...";
                        UploadDetails.Visible = true;
                    }
                else if (nameOfRingtoneTextBox.Text.Contains(".").Equals(true) || nameOfRingtoneTextBox.Text.Contains(" ").Equals(true))
                    {
                        UploadDetails.Text = "Name of Ringtone must not be blank or contain space or contain dot...";
                        UploadDetails.Visible = true;
                    }
                else if (!ringtoneUpload.PostedFile.ContentType.Equals("audio/x-m4r"))
                    {
                        UploadDetails.Text = "Please only select a .m4r file to upload...";
                        //UploadDetails.Text = ringtoneUpload.PostedFile.ContentType.ToString();
                        UploadDetails.Visible = true;
                    }
                else
                {
                    // Display the uploaded file's details
                    UploadDetails.Text = string.Format(@"Uploaded file: {0}<br />  File size (in bytes): {1:N0}<br />  Content-type: {2}", ringtoneUpload.FileName, ringtoneUpload.FileBytes.Length, ringtoneUpload.PostedFile.ContentType);
                    UploadDetails.Visible = true;

                    // Save details into database
                    MembershipUser userObject = Membership.GetUser();
                    string UserName = userObject.ToString();
                    Object userId = userObject.ProviderUserKey;
                    string ringtonePath = "~/Ringtones/" + nameOfRingtoneTextBox.Text + ".m4r";
                    DateTime uploadDateTime = DateTime.Now;

                    string ConnString;

                    ConnString = "Data Source=DEREK-PC;Initial Catalog=iMakeTonesDatabase;Integrated Security=SSPI";

                    SqlConnection SQLConn = new SqlConnection();
                    SqlCommand SQLCmd = new SqlCommand();

                    SQLCmd.CommandType = CommandType.Text;
                    SQLCmd.CommandText = "INSERT INTO [RINGTONE] ([ringtoneName], [userId], [uploadDate], [ringtonePath],[genreId]) VALUES (@ringtoneName,@userId,@uploadDate,@ringtonePath,@genreId)";

                    SqlParameter p1 = SQLCmd.CreateParameter();
                    p1.ParameterName = "@ringtoneName";
                    p1.SqlDbType = SqlDbType.NVarChar;
                    p1.Value = nameOfRingtoneTextBox.Text;
                    SQLCmd.Parameters.Add(p1);

                    SqlParameter p2 = SQLCmd.CreateParameter();
                    p2.ParameterName = "@userId";
                    p2.SqlDbType = SqlDbType.UniqueIdentifier;
                    p2.Value = userId;
                    SQLCmd.Parameters.Add(p2);

                    SqlParameter p3 = SQLCmd.CreateParameter();
                    p3.ParameterName = "@uploadDate";
                    p3.SqlDbType = SqlDbType.DateTime;
                    p3.Value = uploadDateTime;
                    SQLCmd.Parameters.Add(p3);

                    SqlParameter p4 = SQLCmd.CreateParameter();
                    p4.ParameterName = "@ringtonePath";
                    p4.SqlDbType = SqlDbType.NVarChar;
                    p4.Value = ringtonePath;
                    SQLCmd.Parameters.Add(p4);

                    SqlParameter p5 = SQLCmd.CreateParameter();
                    p5.ParameterName = "@genreId";
                    p5.SqlDbType = SqlDbType.NVarChar;
                    p5.Value = DropDownList1.SelectedValue;
                    SQLCmd.Parameters.Add(p5);

                    SQLConn.ConnectionString = ConnString;
                    SQLConn.Open();

                    SQLCmd.Connection = SQLConn;
                    SQLCmd.ExecuteNonQuery();
                    SQLConn.Close();

                    // Save the file
                    string filePath = Server.MapPath("~/Ringtones/" + nameOfRingtoneTextBox.Text + ".m4r");
                    ringtoneUpload.SaveAs(filePath);
                }
            }

            protected void searchRingtonesButton_Click(object sender, EventArgs e)
            {
               
            }

            private void searchRingtonesGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
            {
                // e.Item is the row of the table where the button was
                // clicked.

                //string productID = e.Item.Cells[5].Text;

                if (e.CommandName == "Download")
                {
                    // Add code here to add the productID item to the cart.
                    int index = Convert.ToInt32(e.CommandArgument);

                    GridViewRow selectedRow = searchRingtonesGridView.Rows[index];
                    TableCell testName = selectedRow.Cells[1];
                    string contact = testName.Text;
                    Label1.Text = "You selected " + contact + ".";

                }
                //searchRingtonesGridView.DataBind();
                //Response.Redirect("http://www.imaketones.com/" + productID);
            }
        }
    }
     

    Thanks in advance!

  • Re: Error with GridView_RowCommand

    06-20-2009, 3:27 PM
    Can you see in your events properties, if Gridview_Rowcommand has been defined?
    If you find my post useful, Mark it as answer!

    Sanchay Subhedar
  • Re: Error with GridView_RowCommand

    06-20-2009, 3:38 PM

     you are using this e.CommandName == "Download

    but in grid nowhere deciared button.commandname.

     

    Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution.

    Srinivas Kotra.


  • Re: Error with GridView_RowCommand

    06-20-2009, 6:27 PM
    Answer
    • All-Star
      26,848 point All-Star
    • PeteNet
    • Member since 01-21-2009, 1:15 PM
    • Posts 3,831

     change the following in the access modifier and it will compile and work:

     

    private void searchRingtonesGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
            { ....etc

    to 

    protected void searchRingtonesGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
            {

    Regards,
    Peter
  • Re: Error with GridView_RowCommand

    06-20-2009, 8:01 PM

     Great catch!

    If you find my post useful, Mark it as answer!

    Sanchay Subhedar
  • Re: Error with GridView_RowCommand

    06-21-2009, 12:08 AM
    • Member
      1 point Member
    • fallenangel13
    • Member since 06-20-2009, 2:21 PM
    • Posts 3

     Thanks...

Page 1 of 1 (6 items)