Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Ajax ModalPopUpExtender control to update one column (Status column) in the GridView. Everything works fine. But what I want now is: When I click on one of these status, I want the Ajax ModalPopUp Window to be opened with specifiying the status in the options listed inside the ModalPopUpExtender. For example, if the status is Approved, and I have four options be listed in the ModalPopUpExtender, the Approved option should be checked or highlighted. **So how to do that?**

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="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">
                    <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: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: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:UpdatePanel>


C# code-behind:
C#
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();
    }

    public void btnSendStatus_Click(object sender, EventArgs e) {
        //get the ID of the selected suggestion/row
        var statusID = StatusList.SelectedValue;


        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdbTest;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))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(updateCommand, conn))
            {
                cmd.Parameters.AddWithValue("@statusID", Convert.ToInt32(statusID));
                cmd.Parameters.AddWithValue("@SafetySuggestionsID", Convert.ToInt32(HiddenField1.Value));
                cmd.ExecuteNonQuery();
            }
            //reset the value of hiddenfield
            HiddenField1.Value = "-1";
        }

        GridView1.DataBind();


        SendSuggestionStatusToUser(statusID);
    }
Posted

1 solution

You need to go like this..

first of generate Row Data Bound event, which will tack care for your check-box/radio button which is checked automatically to previous entry while your bind the data to your grid.

Radio button checked issue for row data bound[^]

bind-radio-button-list-to-column-in-gridview[^]


for highlighting your radio button you can use css for it..

CSS
input[type=radio]:checked {  
   border: 1px solid black;
   color: red;
} 


it will highlight your radio button which is selected or checked.
 
Share this answer
 
Comments
matrix388 7-Jul-12 5:24am    
The RadioButtonList is a part of the Ajax ModalPopUpExtender control not the GridView. So how to show the pre-defined item in the GridView in the ModalPopUpExtender.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900