i have gridview in which i have added dropdown list and button .On Rowdatabound event i am filling dropdown list On Button click i want to check selected item in drop down list at clientside at the same row how i can do this.i was able to add script for confirm message on button like this:
我有gridview,其中我添加了下拉列表和按钮。在Rowdatabound事件我填充下拉列表按钮单击我想检查在同一行的客户端下拉列表中的选定项目如何我可以做到这一点。我能够在按钮上添加确认消息的脚本,如下所示:
<script type="text/javascript">
function confirmpo() {
if (confirm("Genrate order for this product?")) {
return true;
}
else {
return false;
}
}
</script>
<asp:GridView ID="grdColorname" runat="server" onrowcommand="grdvendorname_RowCommand" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="Company Id" Visible="false"/>
<asp:BoundField DataField="Productname" HeaderText="Product name" />
<asp:TemplateField HeaderText="Actions" >
<ItemTemplate>
<asp:DropDownList ID="lstvendor" runat="server">
<asp:ListItem Text="Select" Value="-1"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:Button ID="btnGenratepo" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' CssClass="btnclassedit" runat="server" CommandName="GenratePO" Text="" ToolTip="Genrate P/O" OnClientClick="javascript:return confirmpo();"/>
</ItemTemplate>
</asp:TemplateField
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
Any Suggestion on how to do this.
有关如何执行此操作的任何建议。
2 个解决方案
#1
0
If I understand correctly, inside confirmpo()
, you want to see the value of the <select>
on the same row as the button?
如果我理解正确,在confirmmpo()中,你想看到与按钮在同一行的
In that case, first you need to look at the rendered HTML of the page. The gridview will be rendered as a table. You can use the event that is passed to confirmpo()
like this:
在这种情况下,首先您需要查看页面的呈现HTML。 gridview将呈现为表格。您可以使用传递给confirmmpo()的事件,如下所示:
function confirmpo(e) {
var btn = e.srcElement;
// .. locate the <select> element
// .. insert rest of the code
}
You should probably go via the parentNode
properties up to the <tr>
, and then get to the <select>
. All of this can be done easier with a DOM traversal library such as jQuery.
您可能应该通过parentNode属性到,然后转到
#2
0
It will look like this not tested
它看起来像没有经过测试
$("#grdColorname input:button").click(function(){
var selectedValue=$(this).parent('td').prev('td').find('input:select').value();
});
the selectedValue will contain your required value for your drop-down list.
selectedValue将包含下拉列表所需的值。
#1
0
If I understand correctly, inside confirmpo()
, you want to see the value of the <select>
on the same row as the button?
如果我理解正确,在confirmmpo()中,你想看到与按钮在同一行的
In that case, first you need to look at the rendered HTML of the page. The gridview will be rendered as a table. You can use the event that is passed to confirmpo()
like this:
在这种情况下,首先您需要查看页面的呈现HTML。 gridview将呈现为表格。您可以使用传递给confirmmpo()的事件,如下所示:
function confirmpo(e) {
var btn = e.srcElement;
// .. locate the <select> element
// .. insert rest of the code
}
You should probably go via the parentNode
properties up to the <tr>
, and then get to the <select>
. All of this can be done easier with a DOM traversal library such as jQuery.
您可能应该通过parentNode属性到,然后转到
#2
0
It will look like this not tested
它看起来像没有经过测试
$("#grdColorname input:button").click(function(){
var selectedValue=$(this).parent('td').prev('td').find('input:select').value();
});
the selectedValue will contain your required value for your drop-down list.
selectedValue将包含下拉列表所需的值。