2016-01-10 87 views
0

下面的代碼會從網格視圖行選擇的值選擇的值與ID dllinvoivceidDropDownList的問題

protected void gridvoucher_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
try 
{ 
string commandName = e.CommandName.ToString().Trim(); 
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);    
string custid = row.Cells[5].Text; 
string invoiceid = row.Cells[4].Text; 
GridViewRow gvRow = (GridViewRow)((Control)e.CommandSource).NamingContainer; 
Int32 rowind = gvRow.RowIndex; 
switch (commandName) 
{ 
case "EditVoucher": 
dllcust.SelectedValue = custid; 
dllinvoivceid.SelectedValue = invoiceid;      
MultiView1.ActiveViewIndex = 1; 
break;     
} 
} 
catch (Exception ex) 
{ 
Response.Write("Error: " + ex.Message); 
} 
} 

下拉列表,你可以從下面的代碼,我把基於dllcust拿到發票限制爲dllinvoivceid見只有被選中的客戶的問題是選定值我得到dllinvoivceid是從網格視圖

<div class="form-group"> 
<label for="InputName"> 
Customer Name</label> 
<div class="form-group"> 
<asp:DropDownList ID="dllcust" CssClass="form-control chosen-select" runat="server" AutoPostBack="True" DataSourceID="Sqls_Cust" DataTextField="Cust_Name" DataValueField="Cust_ID"></asp:DropDownList> 
<asp:SqlDataSource ID="Sqls_Cust" runat="server" ConnectionString="<%$ ConnectionStrings:ConnString %>" SelectCommand="SELECT [Cust_ID], [Cust_Name] FROM [Customer]"></asp:SqlDataSource> 
</div> 
</div> 
<div class="form-group"> 
<label for="InputName"> 
Invoice ID</label> 
<div class="form-group"> 
<asp:DropDownList ID="dllinvoivceid" CssClass="form-control chosen-select" runat="server" AutoPostBack="True" DataSourceID="Sqlds_Invoive" DataTextField="InvoiceID" DataValueField="InvoiceID"></asp:DropDownList> 
<asp:SqlDataSource ID="Sqlds_Invoive" runat="server" ConnectionString="<%$ ConnectionStrings:ConnString %>" SelectCommand="SELECT Invoice.InvoiceID FROM Customer INNER JOIN Invoice ON Customer.Cust_ID = Invoice.Cust_ID WHERE (Customer.Cust_ID = @Cust_ID)"> 
<SelectParameters> 
<asp:ControlParameter ControlID="dllcust" Name="Cust_ID" PropertyName="SelectedValue" /> 
</SelectParameters> 
</asp:SqlDataSource> 
</div> 
</div> 

回答

1

dllinvoivceid不是值選擇命令的第一個結果您應該使用SelectedIndex,例如

dllinvoivceid.SelectedIndex=dllinvoivceid.Items.IndexOf(ddlData.Items.FindByText(invoiceid)); 
+0

嗨ddlData代表什麼? – Ayman

+0

由於錯誤而感到遺憾 – SAL

+0

dllinvoivceid.SelectedIndex = dllinvoivceid.Items.IndexOf(dllinvoivceid.Items.FindByText(invoiceid)); – SAL