将 Value 设置为 Detailview1 的绑定字段?

发布于 2024-12-11 08:42:25 字数 3816 浏览 0 评论 0原文

这是我的 DetailView1.. 我想在 asp.net 中的页面加载时设置详细信息视图的边界字段的值。所以请仔细阅读我的代码,我希望你能准确理解我想要的东西。

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        CellPadding="4" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
        ForeColor="#333333" GridLines="None" Height="50px" Width="125px" 
          onpageindexchanging="DetailsView1_PageIndexChanging">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <RowStyle BackColor="#EFF3FB" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="branchid" HeaderText="branchid" 
                InsertVisible="False" ReadOnly="True" SortExpression="branchid" />
            <asp:BoundField DataField="branchcode" HeaderText="branchcode" 
                SortExpression="branchcode" />
            <asp:BoundField DataField="password" HeaderText="password" 
                SortExpression="password" />
            <asp:BoundField DataField="branchname" HeaderText="branchname" 
                SortExpression="branchname" />
            <asp:BoundField DataField="contactperson" HeaderText="contactperson" 
                SortExpression="contactperson" />
            <asp:BoundField DataField="contactnumber" HeaderText="contactnumber" 
                SortExpression="contactnumber" />
            <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
            <asp:BoundField DataField="address" HeaderText="address" 
                SortExpression="address" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:vhostdom_demoConnectionString1 %>" 
        InsertCommand="INSERT INTO branch_master(branchcode, password, branchname, contactperson, contactnumber, email, address) VALUES (@branchcode, @password, @branchname, @contactperson, @contactnumber, @email, @address)" 
        SelectCommand="SELECT branchid, branchcode, password, branchname, contactperson, contactnumber, email, address, status FROM branch_master">
        <InsertParameters>
            <asp:SessionParameter Name="branchcode" SessionField="branchcode" />
            <asp:Parameter Name="password" />
            <asp:Parameter Name="branchname" />
            <asp:Parameter Name="contactperson" />
            <asp:Parameter Name="contactnumber" />
            <asp:Parameter Name="email" />
        </InsertParameters>
    </asp:SqlDataSource>

我需要在页面加载时将值设置为分支代码 boudfield 值, 像这样...

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class admin_admin_add_branch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //This is what exactly i want...Example 

        DetailView1.control("branchcode").value = "Now i can set value to a boundfield on page load :)";
    }
}

请帮我解决这个问题...并提前谢谢你...!

This is My DetailView1.. i want to set value for detailsview's boundfield on page load in asp.net. so please go through my code, i hope that you can understand what i want exactly.

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        CellPadding="4" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
        ForeColor="#333333" GridLines="None" Height="50px" Width="125px" 
          onpageindexchanging="DetailsView1_PageIndexChanging">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <RowStyle BackColor="#EFF3FB" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="branchid" HeaderText="branchid" 
                InsertVisible="False" ReadOnly="True" SortExpression="branchid" />
            <asp:BoundField DataField="branchcode" HeaderText="branchcode" 
                SortExpression="branchcode" />
            <asp:BoundField DataField="password" HeaderText="password" 
                SortExpression="password" />
            <asp:BoundField DataField="branchname" HeaderText="branchname" 
                SortExpression="branchname" />
            <asp:BoundField DataField="contactperson" HeaderText="contactperson" 
                SortExpression="contactperson" />
            <asp:BoundField DataField="contactnumber" HeaderText="contactnumber" 
                SortExpression="contactnumber" />
            <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
            <asp:BoundField DataField="address" HeaderText="address" 
                SortExpression="address" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:vhostdom_demoConnectionString1 %>" 
        InsertCommand="INSERT INTO branch_master(branchcode, password, branchname, contactperson, contactnumber, email, address) VALUES (@branchcode, @password, @branchname, @contactperson, @contactnumber, @email, @address)" 
        SelectCommand="SELECT branchid, branchcode, password, branchname, contactperson, contactnumber, email, address, status FROM branch_master">
        <InsertParameters>
            <asp:SessionParameter Name="branchcode" SessionField="branchcode" />
            <asp:Parameter Name="password" />
            <asp:Parameter Name="branchname" />
            <asp:Parameter Name="contactperson" />
            <asp:Parameter Name="contactnumber" />
            <asp:Parameter Name="email" />
        </InsertParameters>
    </asp:SqlDataSource>

I need to set value to branchcode boudfield value on page load,
like this...

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class admin_admin_add_branch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //This is what exactly i want...Example 

        DetailView1.control("branchcode").value = "Now i can set value to a boundfield on page load :)";
    }
}

Please Help me to solve this issue... and advance thanks to you...!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-12-18 08:42:25

首先修复SqlDataSource中SelectCommand的文本:

SelectCommand="SELECT branchid, branchcode, password, branchname, contactperson, contactnumber, email, address, status FROM branch_master where branchcode = @branchcode">

之后重写Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostback){ Session["branchcode"] = "1"; }
}

At the first fix the SelectCommand's text in SqlDataSource:

SelectCommand="SELECT branchid, branchcode, password, branchname, contactperson, contactnumber, email, address, status FROM branch_master where branchcode = @branchcode">

After that rewrite the Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostback){ Session["branchcode"] = "1"; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文