Click here to Skip to main content
13,094,732 members (87,879 online)
Rate this:
Please Sign up or sign in to vote.
In a web-based ASP.NET suggestions box program, the Admin will be able to see all suggestions listed in a GridView control with the username of the owner. In the last column of the GridView, the status will be listed there. When the Admin clicks on the status of one of these suggestion, a new pop-up window ( ajax ModalPopUpExtender) will be appeared with listing all the possible status such as: actioned, approved... etc. And when the Admin selects one of these status, the status of the suggestion will be updated in the database. Everything works fine. What I want to do now is when the user updates the status of anyone of the suggestions, an email notification will be sent to the owner regarding the update of status of his suggestion.

I already wrote the Mail function but I don't know why it does not send any email and I am getting this error while debugging the code:

Use of unassigned local variable 'description'

I already assigned it to the value of the [Description] column in the database but I don't know why I am getting this error.

Could anyone help me with this?

I am really struggling with getting the username of that updated suggestion. FYI, I have the following database design:

Employee Table: Username, Name...
    SafetySuggestionsLog: ID, Title, Description, Username, StatusID
    SafetySuggestionsStatus: ID, Status

**ASP.NET code:**
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID"
                            width="900px" CssClass="mGrid"
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="alt" />
                <HeaderStyle Font-Bold = "True" ForeColor="Black" Height="20px"/>
                    <asp:BoundField DataField="ID" HeaderText="No." InsertVisible="False"
                        ReadOnly="True" SortExpression="ID" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Description" HeaderText="Description"
                        SortExpression="Description" />
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Username" HeaderText="Username"
                        SortExpression="Username" />
                    <asp:BoundField DataField="DivisionShortcut" HeaderText="Division"
                        SortExpression="DivisionShortcut" />
                    <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                    <%-- This to make status be opened and edited through the Ajax ModalPopUp Window --%>
                    <asp:TemplateField HeaderText="Status">
                            <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                    <%--<asp:HyperLinkField HeaderText="Status"
                        SortExpression="Status" />--%>
                <RowStyle HorizontalAlign="Center" />
            <asp:Button runat="server" ID="btnModalPopUp" style="display:none" />
            <AjaxToolkit:ModalPopUpExtender ID="modalPopUpExtender1"
            <asp:HiddenField ID="HiddenField1" runat="server"/>
            <asp:Panel runat="server" ID="pnlPopUp" CssClass="popUpStyle">
                        <asp:RadioButtonList ID="StatusList" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
                                                RepeatLayout="Table" TextAlign="Right" DataSourceID="SuggestionStatusDataSource"
                                                DataTextField="Status" DataValueField="ID">
                            <asp:ListItem id="option1" runat="server" Value="ACTIONED" />
                            <asp:ListItem id="option2" runat="server" Value="APPROVED" />
                            <asp:ListItem id="option3" runat="server" Value="PENDING" />
                            <asp:ListItem id="option4" runat="server" Value="TRANSFERRED" />
                        <asp:SqlDataSource ID="SuggestionStatusDataSource" runat="server"
                                            ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                                            SelectCommand="SELECT * FROM [SafetySuggestionsStatus]"></asp:SqlDataSource>
                        <asp:Button ID="confirmButton" runat="server" Text="Confirm"
                                    OnClientClick="javascript:return confirm('Are you sure you want to send an email notification about the safety suggestion to the owner?')"
                                    OnClick="btnSendStatus_Click" />
                <asp:Button ID="OKButton" runat="server" Text="Close" />

    protected void lnkSuggestionStatus_Click(object sender, EventArgs e)
            LinkButton lnkSuggestionStatus = sender as LinkButton;
            //var safetySuggestionsId =
            //get reference to the row selected
            GridViewRow gvrow = (GridViewRow)lnkSuggestionStatus.NamingContainer;
            //set the selected index to the selected row so that the selected row will be highlighted
            GridView1.SelectedIndex = gvrow.RowIndex;
            //This HiddenField used to store the value of the ID
            HiddenField1.Value = GridView1.DataKeys[gvrow.RowIndex].Value.ToString();
            //ViewState["Username"] = gvrow.Cells[4].Text;
            //show the modalPopUp
        public void btnSendStatus_Click(object sender, EventArgs e) {
            //get the ID of the selected suggestion/row
            var statusID = StatusList.SelectedValue;
            var safetySuggestionsID = HiddenField1.Value;
            string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=xxdb;Integrated Security=True";
            //For updating the status of the safety suggestion
            string updateCommand = "UPDATE SafetySuggestionsLog SET StatusID= @statusID where ID=@SafetySuggestionsID";
            using (SqlConnection conn = new SqlConnection(connString))
                using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
                    cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                    cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                //reset the value of hiddenfield
                HiddenField1.Value = "-1";


***Note: I know that I should not post a lengthy code here, but because I want to explain to you my work and to get your help.***

I modified my code regarding assigning the variables to NULL and when I debugged the code, I found that the reader doesn't work and it did not read the following:
<pre lang="c#">    if (reader != null)
                        if (reader.Read())
                            username = reader["Username"].ToString();
                            description = reader["Description"].ToString();
                            status = reader["Status"].ToString();

**UPDATE 2:**

In the `SendSuggestionStatusToUser(string suggestionID)` method, I added break point to the following line:

string safetySuggestionID = suggestionID.ToString();

and I added break point to the following line:

cmd.Parameters.AddWithValue("@safetySuggestionID", Convert.ToInt32(HiddenField1.Value));

And I found that for the first one, the safetySuggestionID got the data from the passed value. However, for the second one the value of `(HiddenField1.Value)`is -1 and I don't know why. Also, I added break points to each one of the following lines:
SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                    if (reader.Read())
                        username = reader["Username"].ToString();
                        description = reader["Description"].ToString();
                        status = reader["Status"].ToString();

And the debugger did not go through them while debugging them. It goes directly to

var sEMailAddresses = sbEmailAddresses.ToString();

And I don't know why. Any idea? Could you please help me?
Posted 7-Jul-12 1:04am
Updated 19-Feb-13 7:26am
Wes Aday 7-Jul-12 16:15pm
As a suggestion, you might want to clean this up a bit. You ask a different question every other sentence and then post code that is totally unrelated to anything. And to make matters worse, you start off with one question ask 5 others and then decide that your real problem is something that is not even remotely related to sending mail.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

string description=string.Empty;

try this
matrix388 7-Jul-12 8:06am
Please see my updated question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100