GV があり、過去 180 日間にアクティブな DB 書き込みを行ったユーザーのリストを動的に作成する必要があります。1 つのページがメンバーシップ ID のユーザー名を取得し、それを Table1 に書き込みます。次に、そのテーブルで SELECT Distinct を実行して DDL を設定し、その値を Table2 に書き込みます。SelectedValue='<%# Bind("DeliverPartTo") %>'
問題は、取得した DDL Selected 値を設定しようとしたときです。
「DDL_DeliverPartTo」には、アイテムのリストに存在しないため無効な SelectedValue があります。パラメータ名: 値
コードは次のとおりです。
<asp:TemplateField HeaderText="DeliverPartTo" SortExpression="DeliverPartTo">
<ItemTemplate>
<asp:DropDownList ID="DDL_DeliverPartTo" runat="server" SelectedValue='<%# Bind("DeliverPartTo") %>' DataSourceID="SQLTechs" DataTextField="RequestedBy" DataValueField="RequestedBy"
Height="25px" Width="135px" AutoPostBack="True" AppendDataBoundItems="true"
OnDataBound="SqlDS_DeliverPartTo_DataBinding" OnSelectedIndexChanged="DDL_DeliverPartTo_SelectedIndexChanged"
>
<asp:ListItem Text="" Enabled="true" Selected="True" Value='-1'></asp:ListItem>
<asp:ListItem Text="Stock" Enabled="true" Value='-1'></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SQLTechs" runat="server"
ConnectionString="<%$ ConnectionStrings:inventory_v2ConnectionString %>"
SelectCommand="SELECT DISTINCT [RequestedBy] FROM [Process_PartRequests]">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:inventory_v2ConnectionString %>"
SelectCommand="SELECT Process_WarrantyTracker.ID, Process_WarrantyTracker.RequestNumber, Process_PartRequests.DateRequested, Process_RequestStatuses.ID AS StatusID,
Process_RequestStatuses.StatusCode, Process_PartRequests.CATicketNumber, Process_PartRequests.SystemSerialNumber,
Models_PriModels.PriModel + '-' + Models_SecModels.SecModel + '-' + Models_FormFactor.Form AS Model, Part_Catalog.OEMPartCode,
Part_Groups.GroupType + ' - ' + Part_Groups.GroupName AS Groups, Process_PartRequests.RequestedBy, Models_OEMs.Manufacturer AS OEM,
Process_WarrantyTracker.DateOrderedFromOEM, Process_WarrantyTracker.OrderedByICGAdmin, Process_WarrantyTracker.OEMWorkOrderNumber,
Process_WarrantyTracker.PartSerialNumber, Process_WarrantyTracker.OrderRecievedDate, Process_WarrantyTracker.DeliverPartTo,
Process_WarrantyTracker.ProblemFlag, Process_WarrantyTracker.PartOfMultiPartOrder, Process_WarrantyTracker.ShipperTrackingNo,
Process_WarrantyTracker.ReturnOrderShipped, Process_WarrantyTracker.Comment1, Process_WarrantyTracker.Comment2
FROM Process_WarrantyTracker INNER JOIN
Process_PartRequests ON Process_WarrantyTracker.RequestNumber = Process_PartRequests.RequestNumber INNER JOIN
Process_RequestStatuses ON Process_PartRequests.RequestStatus = Process_RequestStatuses.ID INNER JOIN
Models ON Process_PartRequests.Model = Models.ID INNER JOIN
Models_FormFactor ON Models.FormFactor = Models_FormFactor.ID INNER JOIN
Models_OEMs ON Models.Manufacturer = Models_OEMs.ID INNER JOIN
Models_PriModels ON Models.PriModel = Models_PriModels.ID INNER JOIN
Models_SecModels ON Models.SecModel = Models_SecModels.ID INNER JOIN
Part_Catalog ON Process_PartRequests.OEMPartCode = Part_Catalog.ID INNER JOIN
Part_Groups ON Part_Catalog.GroupType = Part_Groups.ID
WHERE Process_RequestStatuses.ID != 4">
</asp:SqlDataSource>
protected void SqlDS_DeliverPartTo_DataBinding(object sender, EventArgs e)
{
try
{
GridViewRow gr = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent;
HiddenField RequestNumber = (HiddenField)gr.FindControl("RequestNumber");
string ReqNum = RequestNumber.Value;
string query = "SELECT [DeliverPartTo] FROM [Process_WarrantyTracker] WHERE [RequestNumber] = @RequestNumber ";
DropDownList DDL_DeliverPartTo = (DropDownList)GridView1.FindControl("DDL_DeliverPartTo");
SqlConnection connectionString = new SqlConnection(ConfigurationManager.ConnectionStrings["inventory_v2ConnectionString"].ConnectionString);
connectionString.Open();
SqlCommand cmd = new SqlCommand(query, connectionString);
Object returnValue;
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@RequestNumber", ReqNum);
cmd.Connection = connectionString;
returnValue = cmd.ExecuteScalar();
connectionString.Close();
DDL_DeliverPartTo.SelectedValue = returnValue.ToString();
}
catch (Exception ex)
{
//Response.Write(ex.Message);
}
}
protected void DDL_DeliverPartTo_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gr = (GridViewRow)((DataControlFieldCell)((DropDownList)sender).Parent).Parent;
DropDownList DDL_DeliverPartTo = (DropDownList)gr.FindControl("DDL_DeliverPartTo");
HiddenField RequestNumber = (HiddenField)gr.FindControl("RequestNumber");
string ReqNum = RequestNumber.Value;
string query = "UPDATE [Process_WarrantyTracker] SET [DeliverPartTo]=@DeliverPartTo WHERE [RequestNumber] = @RequestNumber ";
SqlConnection connectionString = new SqlConnection(ConfigurationManager.ConnectionStrings["inventory_v2ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(query, connectionString);
cmd.Connection.Open();
cmd.Parameters.Add("@DeliverPartTo", DDL_DeliverPartTo.SelectedValue);
cmd.Parameters.Add("@RequestNumber", ReqNum);
cmd.CommandType = CommandType.Text;
Object ddlValues;
ddlValues = cmd.ExecuteScalar();
cmd.Connection.Close();
cmd.Connection.Dispose();
Response.Redirect("Admin-WarrantyTracker.aspx");
}