I am a new ASP.NET developer and I am developing a web-based suggestions box program for my company where the employees can submit any safety suggestions they have. Now, I am working on the Administration part of this system.
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
(asp.net 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 notfication 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 how to get the username of that selected suggestion that its status has been updated. Could anyone help me with this?**
I am really struggling with getting the username of that updated suggestion.
//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
modalPopUpExtender1.Show(); }
matrix388
Member
47 Points
92 Posts
How to send an email notification about updating the status of the suggestion to its owner?
Jul 04, 2012 10:34 AM|LINK
I am a new ASP.NET developer and I am developing a web-based suggestions box program for my company where the employees can submit any safety suggestions they have. Now, I am working on the Administration part of this system.
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 (asp.net 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 notfication 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 how to get the username of that selected suggestion that its status has been updated. 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"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" width="900px" CssClass="mGrid" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" CssClass="alt" /> <HeaderStyle Font-Bold = "True" ForeColor="Black" Height="20px"/> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" 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="DivisionShortcut" 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"> <ItemTemplate> <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>' OnClick="lnkSuggestionStatus_Click"> </asp:LinkButton> </ItemTemplate> </asp:TemplateField> <%--<asp:HyperLinkField HeaderText="Status" SortExpression="Status" />--%> </Columns> <RowStyle HorizontalAlign="Center" /> </asp:GridView> <asp:Button runat="server" ID="btnModalPopUp" style="display:none" /> <AjaxToolkit:ModalPopUpExtender ID="modalPopUpExtender1" runat="server" TargetControlID="btnModalPopUp" PopupControlID="pnlPopUp" BackgroundCssClass="popUpStyle" PopupDragHandleControlID="panelDragHandle" OkControlID="OKButton"> </AjaxToolkit:ModalPopUpExtender> <asp:Panel runat="server" ID="pnlPopUp"> <asp:RadioButtonList ID="StatusList" runat="server" RepeatColumns="1" RepeatDirection="Vertical" RepeatLayout="Table" TextAlign="Left" 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:RadioButtonList> <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" /> </asp:Panel> </ContentTemplate> </asp:UpdatePanelNote: 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.
sql server csharp
karthicks
All-Star
31334 Points
5414 Posts
Re: How to send an email notification about updating the status of the suggestion to its owner?
Jul 04, 2012 10:48 AM|LINK
hi, you can get the UserName from grid like below
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
modalPopUpExtender1.Show();
}
while sending mail you can read like below
protected void SendSuggestionStatusToUser(string status)
{
String userName = ViewState["UserName"].ToString();
.................
Karthick S
matrix388
Member
47 Points
92 Posts
Re: How to send an email notification about updating the status of the suggestion to its owner?
Jul 04, 2012 12:10 PM|LINK
Thanks. However, could you please show me how I will be able to send emails?