if (!IsPostBack) {
ZHLbookshop.Model.Books book = new ZHLbookshop.Model.Books();
ZHLbookshop.BLL.Books bll = new ZHLbookshop.BLL.Books();
book = bll.GetModel(int.Parse(Request.QueryString["ts_BooksId"].ToString())); BookNameTextBox.Text = book.ts_BookName;
tsdlDropDownList.SelectedValue = Convert.ToString(book.tsdl_TypeId);
tsxlDropDownList.SelectedValue = Convert.ToString(book.tsxl_TypeId);
tsxxlDropDownList.SelectedValue = Convert.ToString(book.tsxxl_TypeId); AuthorTextBox.Text = book.ts_Author;
PublishingTextBox.Text = book.ts_Publishing;
PublishDateTextBox.Text = book.ts_PublishDate;
ISBNTextBox.Text = book.ts_ISBN;
EditionTextBox.Text = Convert.ToString(book.ts_Edition); DropDownList1.SelectedValue= book.ts_Format;//就是这句出错了 PagesTextBox.Text = Convert.ToString(book.ts_Pages);
PriceTextBox.Text = Convert.ToString(book.ts_Price);
DiscountPriceTextBox.Text = Convert.ToString(book.ts_DiscountPrice);
DiscountDropDownList.SelectedValue = book.ts_Discount;
PicksDropDownList.Text = Convert.ToString(book.ts_Picks);
BargainDropDownList.Text = Convert.ToString(book.ts_Bargain);
ExclusiveDropDownList.Text = Convert.ToString(book.ts_Exclusive); AllSumTextBox.Text = Convert.ToString(book.ts_AllSum);
InformationTextBox.Text = book.ts_Information;
PicksNRTextBox.Text = book.ts_PicksNR;
} }
也就是载入时,就是显示数据的
有些数据运行成功,有些运行出错,这个DropDownList1是用数据库邦定的代码如下asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource5" DataTextField="ts_Format"
DataValueField="ts_Format">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:ZHLbookshop1 %>"
SelectCommand="SELECT * FROM [FormatType]"></asp:SqlDataSource>
ZHLbookshop.Model.Books book = new ZHLbookshop.Model.Books();
ZHLbookshop.BLL.Books bll = new ZHLbookshop.BLL.Books();
book = bll.GetModel(int.Parse(Request.QueryString["ts_BooksId"].ToString())); BookNameTextBox.Text = book.ts_BookName;
tsdlDropDownList.SelectedValue = Convert.ToString(book.tsdl_TypeId);
tsxlDropDownList.SelectedValue = Convert.ToString(book.tsxl_TypeId);
tsxxlDropDownList.SelectedValue = Convert.ToString(book.tsxxl_TypeId); AuthorTextBox.Text = book.ts_Author;
PublishingTextBox.Text = book.ts_Publishing;
PublishDateTextBox.Text = book.ts_PublishDate;
ISBNTextBox.Text = book.ts_ISBN;
EditionTextBox.Text = Convert.ToString(book.ts_Edition); DropDownList1.SelectedValue= book.ts_Format;//就是这句出错了 PagesTextBox.Text = Convert.ToString(book.ts_Pages);
PriceTextBox.Text = Convert.ToString(book.ts_Price);
DiscountPriceTextBox.Text = Convert.ToString(book.ts_DiscountPrice);
DiscountDropDownList.SelectedValue = book.ts_Discount;
PicksDropDownList.Text = Convert.ToString(book.ts_Picks);
BargainDropDownList.Text = Convert.ToString(book.ts_Bargain);
ExclusiveDropDownList.Text = Convert.ToString(book.ts_Exclusive); AllSumTextBox.Text = Convert.ToString(book.ts_AllSum);
InformationTextBox.Text = book.ts_Information;
PicksNRTextBox.Text = book.ts_PicksNR;
} }
也就是载入时,就是显示数据的
有些数据运行成功,有些运行出错,这个DropDownList1是用数据库邦定的代码如下asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource5" DataTextField="ts_Format"
DataValueField="ts_Format">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:ZHLbookshop1 %>"
SelectCommand="SELECT * FROM [FormatType]"></asp:SqlDataSource>
解决方案 »
- 数据库数据转移及图片
- 求一SQL语句解释
- 请问在ASP.NET里面,登录界面有两种登录方式,怎么样阻止用户绕过登陆界面在地址拦里面输入地址直接进入系统?
- 控件如何点击变色?
- 怎么设置日期格式字符串啊,
- 找不到文件或程序集名称“Interop.ADODB”,或找不到它的一个依赖项。
- 第一个项目遇到问题了!1,在table表里面怎么插入图片.2,怎么把该图片存入数据库的字段中...
- 怎么实现文本框中显示“输入关键字” 鼠标点击后就消失了
- 急 !等待 !!!如何设定动态生成的控件在*.aspx窗体中的位置
- 不會到服務器執行Text_change事件,怎樣辦﹖
- XML文档读到DataTable里面怎么成了这样?
- 如何设置从数据库读出来的时间样式.
book.ts_Format的内容不在 DropDownList1 的选项中。
你应该这样
ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
if(x!=null) x.Selected=true;另外,这个操作是在绑定玩数据之后进行的
你打印出
book.ts_Format是什么?
DropDownList1里面有你需要的值吗?注意是Value不是Text
如果book.ts_Format不在你的DropDownList1里面,是不能设置的
asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource5" DataTextField="ts_Format"
DataValueField="ts_Format">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:ZHLbookshop1 %>"
SelectCommand="SELECT * FROM [FormatType]"></asp:SqlDataSource>这个时就出错了
ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
if(x!=null) x.Selected=true;
是在绑定之后设置的吗?
ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
if(x!=null) x.Selected=true;是放在哪里,是不是放在这个
DropDownList1.SelectedValue= book.ts_Format;//就是这句出错了
地方,我试过放在这里没有错误,但它显示的内容与我数据库的内容不一样啊,跟不要这个DropDownList1东西是一样的
另外,你要搞清楚,是Value还是Text为你的book.ts_Format的值,如果是Vlaue,使用ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
if(x!=null) x.Selected=true;
如果是Text则需要使用
ListItem x = DropDownList1.Items.FindByText(book.ts_Format);
if(x!=null) x.Selected=true;