How to use a gridview cell's value as a control parameter
I have an asp.net (VB) web app that has 7 columns. The 5th column has a seperate DataSource than the rest of the columns. I want to use the value from the first column as a ControlParamter (or SessionParamter if that works) in the SelectParameter of that column.
Is that Possible? Attached is partial code of what I've tried for my SelectParameters.
<asp:SqlDataSource ID="neccoLocation" runat="server" ConnectionString="<%$ ConnectionStrings:necco40 %>" SelectCommand="SELECT DISTINCT in_locn_key FROM in_stock_tbl WHERE gl_cmp_key = 'NE' AND in_whs_key = '12' AND (in_locn_key NOT IN ('warehouse', 'staging', 'shortage')) AND (in_locn_key NOT LIKE 'r%') AND (in_locn_key NOT LIKE 's%') AND (in_locn_key NOT LIKE 'q%') AND (in_locn_key NOT LIKE 'w%') AND (in_locn_key NOT LIKE '3%') AND (in_locn_key NOT LIKE '5%') AND (in_locn_key <> '67ship') AND (in_locn_key NOT LIKE 'area%') AND (in_locn_qoh > '0') AND (in_item_key = '@lblIngred') "> <SelectParameters> <asp:ControlParameter ControlID='<%# gvIngredients.FindControl("lblIngred") %>' PropertyName="Text" Name="lblIngred" Type="String" /> <asp:SessionParameter Name="lblIngred" SessionField="lblIngred" /> </SelectParameters> </asp:SqlDataSource>
Great suggestion, but I'm getting the following error message:
"The variable name '@lblIngred' has already been declared. Variable names must be unique within a query batch or stored procedure".
I'm trying to throw your code into a For Each Row loop to hopefully increment the variable name on each row, but that's been a little tricky. I'm going to keep trying...any other suggestions on why I'm getting this error and how to fix would be much appreciated.