Right now, I have a database field named ‘PROCESS_FLAG’ that contains the text value (A, I, E, C) and I want to be able to change the default selected value of my dropdownlist column depending on the value of PROCESS_FLAG and I’m not sure where to go from here.
Here is the code for the GridView that I have:
<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>
I want to set the default selected value of the drop down list depending on the value of PROCESS_FLAG.
Any help with this would be greatly appreciated. I am not a pro at all with the Eval function.
Thanks!
add a OnRowDataBound attribute to the gridview in the .aspx page:
Then, replace
with
Then in your code behind, do something like this:
this should get you a little further 🙂