Click here to Skip to main content
15,936,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a select statement in code infront as following:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:VSGIHURConnectionString %>"
   SelectCommand="SELECT distinct size,UniformID FROM [uniforminfo] where UniformName='+lbl_uniformid+' and status= 'a' ORDER BY UniformID">
   </asp:SqlDataSource>


the UniformName is based on the selection of lbl_uniformid in the grid. The question is how can i rewrite the above sql statement "where UniformName='+lbl_uniformid+'" based on the user selected uniformid (means when user choose a uniformid in the grid then the select statement will select a correct size based on the user chosen uniformid)?

Here is the code of UniformName in the grid

XML
<asp:TemplateField HeaderText="Type Of Uniform" Visible="true" ItemStyle-Width="200" >
        <ItemTemplate>
            <asp:Label ID="lbl_uniformid" runat="server" Text='<%#Eval("uniformgroupname") %>'
                Visible="true"></asp:Label>

        </ItemTemplate>
          <EditItemTemplate>
         <asp:TextBox ID="ddl_uniformgroupname" runat="server" AutoPostBack="true" runat="server"
            BackColor="White" CompletionListCssClass="completeListStyle"
            Text='<%# Eval("uniformgroupname") %>' ontextchanged="txt_ddl_uniformgroupname"
            style="font-family: 'Century Gothic';" Visible="true"
            >
        </asp:TextBox>
        <asp:AutoCompleteExtender ID="ddl_uniformgroupname_AutoCompleteExtender" runat="server" CompletionInterval="100"
    CompletionListCssClass="completeListStyle" DelimiterCharacters="" Enabled="True"
    MinimumPrefixLength="0" ServiceMethod="GetCompletion_ddl_uniformgroupname" ServicePath=""
    TargetControlID="ddl_uniformgroupname">
</asp:AutoCompleteExtender>
    
     </EditItemTemplate>
    </asp:TemplateField>



Appreciate to anyone who want to assist my problem.

Thanks a lot & H@ppy 2013.

sp
Posted

1 solution

The way you are doing this, is totally wrong. You need to use Parameters in SqlDataSource Control. It seems you need to do a lots of practice on it. Just visit the below links:
Using Parameters with the SqlDataSource Control[^]
Use a SqlParameter to represent stored procedure return values and output parameters[^]
SqlParameter Example, How to use SqlParameter in ASP.Net C#, SqlParameter, SqlDataReader, SqlCommand, SqlConnection Example[^]


--Amit
 
Share this answer
 
Comments
singping 31-Dec-12 6:13am    
Thanks to your information, especially the 1st link is quite helpful to me.
_Amy 31-Dec-12 7:10am    
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900