详细信息视图中的运行时更新命令 [英] runtime updatecommand in detailsview

查看:63
本文介绍了详细信息视图中的运行时更新命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用Detailsview控件,并且在其中添加了update命令字段.在运行时,我需要显示表中的特定记录,并在运行时更新该记录.在更新中,选择命令我要在运行时来自会话页面的会话值中使用where条件中的值.

下面,我在where条件中添加了具有静态值的代码.如何在where条件中使用动态/会话值.

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: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>

推荐答案

Connectionstrings:con1%>" SelectCommand =" UpdateCommand =" 运行 =" / > < > < tr > td < asp:DetailsView ID =" runat =" span> DataSourceID =" AutoGenerateRows =" BackColor =" ForeColor =" BorderColor =" OnItemUpdating =" AllowPaging =" 字体粗体 =" 字体大小 =" GridLines =" 无" 宽度 317px" > < 字段 > < asp:BoundField HeaderText =" DataField staffname " / < asp:BoundField HeaderText =" DataField qualify " / < asp:BoundField HeaderText =" DataField 名称" / < asp:BoundField HeaderText =" DataField 地址" / < asp:BoundField HeaderText =" DataField ctno" / < asp:BoundField HeaderText =" DataField =" dob" / > < asp:BoundField HeaderText =" DataField 薪水" / < asp:BoundField HeaderText =" DataField =" 加入日期" / < asp:BoundField HeaderText =" 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 =" / < /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>
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>


这篇关于详细信息视图中的运行时更新命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆