我想在gridview rowcommand事件中访问dropdownlist选择的项值

时间:2013-12-03 11:05:46

标签: asp.net

<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"></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" /> 
          </td>
      </tr>
    </table>                    
</div>

点击

动态填充上面的div
<img alt="Details" id="img<%# Eval("suggestion_no") %>" src="images/plus.png" />

现在我想通过点击图片按钮访问所选项目,即ibSubmit

<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">

                               </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" /> 
                                </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>

1 个答案:

答案 0 :(得分:0)

试试这个

给你的按钮一个命令参数,以帮助你跟踪被点击的行

<强>标记

 <asp:ImageButton ID="ibSubmit" runat="server" ImageUrl="~/images/submit-button.png"  AlternateText="Submit" CommandName="Submit" CommandArgument="<%# Eval("suggestion_no")%>" /> 

Cod落后

在你的行命令事件中,将命令参数强制转换为int

           int index=Convert.ToInt32(e.CommandArgument.toString);

然后使用该索引找到您的下拉列表

Dropdownlist ddlICM=(DropdownList)yourGridView.Rows(index).FindControl("ddlICM");
String yourValue=ddlICM.selectedValue;