我有一個包含以下GridView
一個DropDownList
它調用基於SelectedValue
的方法:如何獲取GridView中的值並將其傳遞給GridView中由DropDownList調用的方法?
在列,其中選擇正在取得,我如何才能從GridView
的Customer ID
它作爲參數傳遞給方法被稱爲下面?
代碼:
<asp:GridView ID="grdLoadData" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Example">
<ItemTemplate>
<asp:DropDownList ID="ddlExampleDropDownList" runat="server"
AutoPostBack="true" Width="100"
OnSelectedIndexChanged="ddlExampleDropDownList_SelectedIndexChanged">
<asp:ListItem Text="---- Select --" Value="select" />
<asp:ListItem Text="Do Task A" Value="Task A" />
<asp:ListItem Text="Do Task B" Value="Task B" />
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LAST_NAME" HeaderText="Last Name" />
<asp:BoundField DataField="FIRST_NAME" HeaderText="First Name" />
<asp:BoundField DataField="MiDDLE_NAME" HeaderText="Middle Name" />
<asp:TemplateField HeaderText="Customer ID">
<ItemTemplate>
<asp:Label ID="lblCustomerID" Text='<%#Eval("CUST_ID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代碼背後:
public string DoTaskA(string customerId)
{
return customerId;
}
public string DoTaskB(string customerId)
{
return customerId;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
protected void ddlExampleDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dropDownList = (DropDownList)sender;
GridViewRow gridViewRow = (GridViewRow)dropDownList.Parent.Parent;
if(dropDownList.SelectedValue=="Task A")
{
//Pass Customer ID here
DoTaskA();
}
else if(dropDownList.SelectedValue=="Task B")
{
//Pass Customer ID here
DoTaskB();
}
}
所以,你想客戶ID傳遞給SelectedIndex_changed方法? – 2015-04-03 05:50:34
是的:當選擇一個值時,無論什麼值,我需要獲取該行的客戶ID並將其傳遞給相應的DoTask'方法'。 – Asynchronous 2015-04-03 05:54:28