Click here to Skip to main content
16,019,263 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
   <script type="text/javascript">
       function divexpandcollapse(divname) {
           var img = "img" + divname;
           if ($("#" + img).attr("src") == "images/plus.png") {
               $("#" + img)
               .closest("tr")
               .after("<tr><td colspan = '100%'>" + $("#" + divname)
               .html() + "</td></tr>");
               $("#" + img).attr("src", "images/minus.png");
           } else {
               $("#" + img).closest("tr").next().remove();
               $("#" + img).attr("src", "images/plus.png");
           }
       }
   </script>


The above method is used to show the dropdownlist in gridview.

XML
<asp:GridView ID="gvSuggestion" runat="server" AllowPaging="false" CssClass="grid"
 AutoGenerateColumns="false" DataKeyNames="id"
   onrowcancelingedit="gvSuggestion_RowCancelingEdit"
        onrowcommand="gvSuggestion_RowCommand" onrowediting="gvSuggestion_RowEditing"
        onrowupdating="gvSuggestion_RowUpdating"
        onrowdatabound="gvSuggestion_RowDataBound" onselectedindexchanged="gvSuggestion_SelectedIndexChanged"
         >
<Columns>



 <asp:TemplateField ItemStyle-Width="20px">
                    <ItemTemplate>
                        <a href="JavaScript:divexpandcollapse('<%# Eval("suggestion_no") %>');">
                            <img alt="Details" id="img<%# Eval("suggestion_no") %>" src="images/plus.png" />
                        </a>
                        <div id="<%# Eval("suggestion_no") %>" style="display: none; padding-left:10%">


                            <table style="border-style:solid;border-width:1px;">
                             <tr>
                            <td colspan="2" align="right"  style=" border:0px none #ffffff;">
                            <center style="background-color:#4F94CD;"> <span >Assign to Innovation Committee Member</span> </center>
                            </td>
                            </tr>
                            <tr>
                            <td style="border:0px none #ffffff">
                            Innovation Committee Member
                            </td>
                           <td style="border:0px none #ffffff">
                           <asp:DropDownList ID="ddlICM" runat="server"  OnSelectedIndexChanged="ddlICM_SelectedIndexChanged" AutoPostBack="true">

                           </asp:DropDownList>
                           </td>
                            </tr>
                            <tr>
                            <td colspan="2" align="right"  style=" border:0px none #ffffff;">
                            <asp:ImageButton ID="ibSubmit" runat="server" ImageUrl="~/images/submit-button.png"  AlternateText="Submit" CommandName="Submit"  onclick="ibSubmit_Click" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                            </td>
                            </tr>
                            </table>

                        </div>
                    </ItemTemplate>
                </asp:TemplateField>



<asp:TemplateField HeaderText=""  HeaderStyle-HorizontalAlign="Center" >
<ItemTemplate>

<asp:ImageButton ID="ibDescription" runat="server" ImageUrl="~/images/ShowButton.png"  AlternateText="Edit" CommandName="edit" />

</ItemTemplate>

</asp:TemplateField>

<asp:boundfield datafield="suggestion_no" headertext="Suggestion NO"  />
<asp:boundfield datafield="suggestion_area" headertext="Subject"  />
<asp:boundfield datafield="active_closed" headertext="status"  />
<asp:boundfield datafield="date_creation" headertext="created date" />


<asp:boundfield datafield="category_desc" headertext="Category"  />
<asp:boundfield datafield="sub_category_desc" headertext="Sub Category"  />

<asp:boundfield datafield="expected_outcome_short_term" headertext="expected outcome short term"  />
<asp:boundfield datafield="expected_outcome_long_term" headertext="expected outcome long term"  />

<asp:boundfield datafield="present_idea_flag" headertext="Whether ready to present the idea before Innovation Task Team"  />

<asp:boundfield datafield="reason_closed" headertext="Closed Remarks" />

<asp:boundfield datafield="date_closure" headertext="Closure Date"  />
<asp:boundfield datafield="auth_unauth" headertext="Auth Status"  />
<asp:boundfield datafield="reason_unauth" headertext="Reason Unauth" />

<asp:boundfield datafield="date_unauth" headertext="Date Unauth"  />

</Columns>

</asp:GridView>




GridViewRow rown = (GridViewRow)((Control)e.CommandSource).NamingContainer;
               ID = Convert.ToInt32(gvSuggestion.DataKeys[rown.RowIndex].Value);
               string Sg = gvSuggestion.Rows[rown.RowIndex].Cells[2].Text;
               objMember.id = ID;
               GridViewRow CR = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
               int index = Convert.ToInt32(e.CommandArgument.ToString());



               DropDownList ddlICM = (DropDownList)gvSuggestion.Rows[index].FindControl("ddlICM");
               String yourValue = ddlICM.SelectedValue;




               if (ddlICM.SelectedIndex > 0)
               {
                   objMember.Pusername = ddlICM.SelectedValue.ToString();
               }
               else
               {
                   ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Please select Innovation Committee Member!');</script>", false);
                   return;
               }


the above code is on rowcommand
but i am not accessed dropdown selected item value on the

C#
<asp:ImageButton ID="ibSubmit" runat="server" ImageUrl="~/images/submit-button.png"  AlternateText="Submit" CommandName="Submit"  onclick="ibSubmit_Click" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />


button click
Posted

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