gpt4 book ai didi

c# - 在 GridView 中对 DropDownList 选定值使用 Eval

转载 作者:太空宇宙 更新时间:2023-11-03 13:59:18 28 4
gpt4 key购买 nike

现在,我有一个名为“PROCESS_FLAG”的数据库字段,其中包含文本值 (A、I、E、C),我希望能够根据以下值更改下拉列表列的默认选定值PROCESS_FLAG,我不确定从这里去哪里。

这是我拥有的 GridView 的代码:

 <asp:BoundField DataField="REQUESTQTY" HeaderText="Request Quantity" 
SortExpression="REQUESTQTY" />
<asp:BoundField DataField="MOVEFROM" HeaderText="Move From"
SortExpression="MOVEFROM" />
<asp:BoundField DataField="MOVETO" HeaderText="Move To"
SortExpression="MOVETO" />
<asp:BoundField DataField="COMPLETEDBY" HeaderText="Completed By"
SortExpression="COMPLETEDBY" Visible="false"/>
<asp:BoundField DataField="COMPLETION_DATE" HeaderText="Completion Date"
SortExpression="COMPLETION_DATE" />
<asp:BoundField DataField="COMMENTS" HeaderText="Comments"
SortExpression="COMMENTS" Visible="false" />
<asp:BoundField DataField="RESPONSETIME" HeaderText="Response Time"
SortExpression="RESPONSETIME" Visible="false" />
<asp:BoundField DataField="PROCESS_FLAG" HeaderText="Process Flag"
SortExpression="PROCESS_FLAG" />
<asp:BoundField DataField="UNIQUEKEY" HeaderText="Unique Key"
SortExpression="UNIQUEKEY" Visible="true" />

<asp:TemplateField HeaderText="Send To...">
<ItemTemplate>
<asp:DropDownList ID="StatusDD" runat="server" AutoPostBack="false" OnSelectedIndexChanged="StatusDD_SelectedIndexChanged">
<asp:ListItem Value="A">Active</asp:ListItem>
<asp:ListItem Value="C">Complete</asp:ListItem>
<asp:ListItem Value="I">In Process</asp:ListItem>
<asp:ListItem Value="E">Error</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

我想根据 PROCESS_FLAG 的值设置下拉列表的默认选择值。

如有任何帮助,我们将不胜感激。我完全不是 Eval 函数的专家。

谢谢!

最佳答案

在.aspx页面的gridview中添加一个OnRowDataBound属性:

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
DataKeyNames="id" OnRowDataBound="GridViewRowEventHandler">

然后,替换

<asp:BoundField DataField="PROCESS_FLAG" HeaderText="Process Flag"
SortExpression="PROCESS_FLAG" />

     <asp:TemplateField>
<ItemTemplate>
<asp:Label ID="process_Flags" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PROCESS_FLAG").ToString()%>'/>
</ItemTemplate>
</asp:TemplateField>

然后在你后面的代码中,做这样的事情:

 protected void GridViewRowEventHandler(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label flag = (Label)e.Row.FindControl("process_Flags");
DropDownList ddl = (DropDownList)e.Row.FindControl("StatusDD");
if (flag.Text == "A")
{
ddl.SelectedValue = "A";
}
//add more conditions here..

}
}

这会让你更进一步 :)

关于c# - 在 GridView 中对 DropDownList 选定值使用 Eval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11086626/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com