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


I'm using Detailsview control, and I have added update command field in it. At runtime I need to display the particular record from the table, and also update that record at runtime. In the update, select command I want to use the value in the where condition from the session value at run time it comes from login page.

Below I have added my code with static value in the where condition. How to I use the dynamic/session value in the where condition.
ASP.NET
 <asp:SqlDataSource ID="MyDataSource"  ConnectionString="<%$Connectionstrings:con1%>"
SelectCommand="SELECT staffname,qualify,designation,address,ctno,dob,salary,dateofjoining,department,branch,subtaken,username FROM staff where id='5'" 
UpdateCommand="Update staff SET staffname=@staffname,qualify=@qualify, designation=@designation,address=@address,
ctno=@ctno, dob=@dob, salary=@salary, dateofjoining=@dateofjoining,department=@department,branch=@branch,subtaken=@subtaken,
username=@username where id='5'"
runat="server"/>
<table><tr><td>
         <asp:DetailsView
             ID="DetailsView2" 
             runat="server"
             DataSourceID="MyDataSource"
             AutoGenerateRows="False"
             BackColor="#FFD7FF"
             ForeColor="#0033CC"
             BorderColor="LightSlateGray"
              OnItemUpdating="UpdateRecord"
             AllowPaging="True" Font-Bold="True" Font-Size="Medium" 
        GridLines="None" Width="317px"
             >
             <fields>
                <asp:BoundField HeaderText="Name" DataField="staffname" />
                <asp:BoundField HeaderText="Qualification" DataField="qualify" />
                <asp:BoundField HeaderText="Designation" DataField="designation" />
                <asp:BoundField HeaderText="Address" DataField="address" />
                <asp:BoundField HeaderText="Contact No" DataField="ctno" />
                <asp:BoundField HeaderText="Date Of Birth" DataField="dob" />
                <asp:BoundField HeaderText="Salary" DataField="salary" />
                <asp:BoundField HeaderText="Date Of Joining" DataField="dateofjoining" />
                <asp:BoundField HeaderText="Department" DataField="department" />
                <asp:BoundField HeaderText="Branch" DataField="branch" />
                <asp:BoundField HeaderText="Subjects Taken" DataField="subtaken" />
                <asp:BoundField HeaderText="User Name" DataField="username" />
              <%--  <asp:BoundField HeaderText="Password" DataField="password" />--%>
                
                 <asp:CommandField ShowEditButton="True" />
                
            </fields>
            <pagersettings mode="NextPreviousFirstLast" firstpagetext="First" lastpagetext="Last" nextpagetext="Next" previouspagetext="Previous" />
            <pagerstyle backcolor="White" forecolor="HotPink" />
            <HeaderStyle BackColor="White" ForeColor="#FF3399" HorizontalAlign="Center" />
             <insertrowstyle wrap="True" />
            <HeaderTemplate>
                <asp:Label ID="Label1" runat="server" Text="Staff Details" Font-Size="Large">
            </HeaderTemplate>
            <alternatingrowstyle backcolor="White" font-bold="True" forecolor="#0033CC" />
        </td></tr></table>
Posted
Updated 14-Dec-11 2:47am
v2

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