将 Value 设置为 Detailview1 的绑定字段?
这是我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先修复SqlDataSource中SelectCommand的文本:
之后重写Page_Load:
At the first fix the SelectCommand's text in SqlDataSource:
After that rewrite the Page_Load: