我想访问dropdownlist选择的项目值,该值在gridview onrowcommand事件中单击gridview行按钮时动态显示 [英] I would like to access dropdownlist selected item value which show dynamically on the click of gridview row button in the gridview onrowcommand event
本文介绍了我想访问dropdownlist选择的项目值,该值在gridview onrowcommand事件中单击gridview行按钮时动态显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script 类型 = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js > < / script >
< script 类型 = text / javascript >
function divexpandcollapse(divname){
va r 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 >
以上方法用于显示gridview中的下拉列表。
< asp:GridView ID = < span class =code-keyword> gvSuggestion runat = server AllowPaging = false CssClass = grid
AutoGenerateColumns = false DataKeyNames = id
onrowcancelingedit = gvSuggestion_RowCancelingEdit
onrowcommand = gvSuggestion_RowCommand onrowediting = gvSuggestion_RowEditing
onrowupdating = gvSuggestion_RowUpdating跨度> < span class =code-attribute>
< span class =code-attribute> onrowdatabound = gvSuggestion_RowDataBound onselectedindexchanged = gvSuggestion_SelectedIndexChanged
>
< 列 >
< asp:TemplateField ItemStyle-Width = 20px >
< ItemTemplate >
< a < span class =code-attribute> href = JavaScript:divexpandcollapse('<% #Eval( suggestion_no)%> '); >
< img alt = 详细信息 id = img <% #Eval( suggestion_no)%> src = images / plus.png / >
< / a >
< div id = <% #Eval( suggestion_no)%> style = display:none; padding-left:10% >
< ; table style < span class =code-keyword> = border-style:solid; border-width:1px; >
< tr >
< td colspan = 2 align = right style = border:0px none #ffffff; >
< center style = background-color:#4F94CD; > < span > 分配给创新委员会成员< / span > < / center >
< / td > ;
< / tr >
< tr >
< td 样式 = border: 0px无#ffffff >
创新委员会成员
< / td >
< td 样式 = border:0px none #ffffff >
< asp :DropDownList ID = ddlICM runat = server OnSelectedIndexChanged = ddlICM_SelectedIndexChanged AutoPostBack = true >
< / asp:DropDownList >
< / td >
< / tr >
< tr >
< td cols pan = 2 align = right style = border:0px none #ffffff; >
< span class =code-keyword>< asp:ImageButton ID = ibSubmit runat = server ImageUrl = 〜/ images / submit-button.png AlternateText = 提交 CommandName = 提交 onclick = ibSubmit_Click CommandArgument = <%#((GridViewRow)Container).RowIndex %> / >
< / td >
< / tr >
< / table >
< / div >
< / ItemTemplate >
< / asp:TemplateField >
< asp:TemplateField HeaderText = HeaderStyle-HorizontalAlign = 中心 >
< ItemTemplate >
< asp:ImageButton ID = ibDescription runat = server ImageUrl = 〜/ images /ShowButton.png\" AlternateText = 编辑 CommandName = 编辑 / >
< / ItemTemplate >
< / asp:TemplateField >
< asp: boundfield datafield = suggestion_no headertext = 建议否 / >
< asp:boundfield datafield = suggestion_area < span class =code-attribute> headertext = 主题 / >
< asp:boundfield datafield = active_closed headertext = status / >
< asp:boundfield datafield = date_creation headertext = 创建日期 / >
< asp:boundfield datafield = category_desc headertext = 类别 / >
< asp:boundfield datafield = sub_category_desc headertext = 子类别 / >
< asp:boundfield datafield = expected_outcome_short_term headertext = 预期结果短期 / >
< asp:boundfield datafield < span class =code-keyword> = expected_outcome_long_term headertext = 预期结果长期 / >
< asp:boundfield datafield = present_idea_flag headertext = 是否准备好在创新任务团队之前提出这个想法 / >
< asp:boundfield datafield = < span class =code-keyword> reason_closed headertext = 已关闭备注 / >
< asp:boundfield datafield = date_closure headertext = 关闭日期 / >
< asp:boundfield datafield = auth_unauth headertext < span class =code-keyword> = 身份验证状态 / >
< 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选择创新委员会成员!');< / script>,false);
返回;
}
以上代码在rowcommand上
但我不是
< asp:ImageButton ID = ibSubmit runat = server ImageUrl = 〜/ images / submit-button.png AlternateText = 提交 CommandName = 提交 onclick = ibSubmit_Click CommandArgument = <%#((GridViewRow)Container).RowIndex%> />
按钮点击
解决方案
(# + img).attr(src)==images / plus.png){
(#+ img)
.closest(tr)
.after(< tr > ; < td colspan =' 100%' > +
(#+ divname)
.html()+< / td > < / tr > 跨度> );
<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.
<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
<asp:ImageButton ID="ibSubmit" runat="server" ImageUrl="~/images/submit-button.png" AlternateText="Submit" CommandName="Submit" onclick="ibSubmit_Click" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
button click
解决方案
("#" + img).attr("src") == "images/plus.png") {
("#" + img) .closest("tr") .after("<tr><td colspan = '100%'>" +
("#" + divname) .html() + "</td></tr>");
这篇关于我想访问dropdownlist选择的项目值,该值在gridview onrowcommand事件中单击gridview行按钮时动态显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文