可以呀
比如:
<ItemTemplate>
<table>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "产品名称") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "产品规格") %></td>
</tr>
</table>
</ItemTemplate>
比如:
<ItemTemplate>
<table>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "产品名称") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "产品规格") %></td>
</tr>
</table>
</ItemTemplate>
解决方案 »
- asp.net url seo优化的问题
- 关于ASP.NET跨页面调用STATIC函数问题
- 如何实现在同一个服务器上的不同站点间的登录信息共享?
- 发布一个数据分页导航控件,免费的
- 求助,子控件问题
- 小女子有题****解决立刻给分,对比着网上的资料用c#开发的activex控件在客户端不显示,在服务器端(开发机上)没问题
- 网站部署出现的错误,没头绪了,高手麻烦指点一下.
- 请问在上海我这样的水平进这个公司值得么?月薪7000+1000左右
- 输入框prompt("文件夹名称:","");
- 怎么实现邮件接收??????
- 系统说SQL在System.Data中不存在
- 再问一个菜问题:用什么工具开发C#程序?
DropDownList.Items.Clear();
while (myReader.reader())
{
DropDownList.Items.Add(myReader["产品名称"].ToString()+" "+myReader["产品规格"].ToString());
}从DropDownList中取数据的时候以空格为分隔符即可
能否使DropDownList中内容可编辑
<%@Import Namespace="System.Data.OleDb" %><%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Selecting and Editing Data in a DataList Control</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}.rHead {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial;
font-size:14pt; font-weight:bold; padding:8px; color:green}
.rItem {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial,sans-serif;
font-size:10pt}
.rFoot {font-family:Tahoma,Arial; font-size:8pt; padding:8px; color:darkgray}</style></head>
<body bgcolor="#ffffff">
<span class="heading">Selecting and Editing Data in a DataList Control</span><hr />
<!---------------------------------------------------------------------------><%// -- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server" /><div id="outError" runat="server" /><ASP:Label id="lblSQL" runat="server" /><p /><form runat="server"> <ASP:DataList id="MyDataList" runat="server"
CellSpacing = "2"
SelectedItemStyle-BackColor="red"
SelectedItemStyle-ForeColor="white"
EditItemStyle-BackColor="yellow"
EditItemStyle-ForeColor="black"
DataKeyField="ISBN"
OnItemCommand="DoItemSelect"
OnEditCommand="DoItemEdit"
OnUpdateCommand="DoItemUpdate"
OnDeleteCommand="DoItemDelete"
OnCancelCommand="DoItemCancel"> <HeaderTemplate>
<b>Some Wrox Press Books:</b><br />
</HeaderTemplate> <ItemTemplate>
<ASP:Button CommandName="Select" Text="Info" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</ItemTemplate> <SelectedItemTemplate>
Title: <b><%# DataBinder.Eval(Container.DataItem, "Title") %></b><br />
<ASP:Button CommandName="Edit" Text="Edit" runat="server" />
ISBN: <%# DataBinder.Eval(Container.DataItem, "ISBN") %>
Published:
<%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}") %>
</SelectedItemTemplate> <EditItemTemplate>
<b>ISBN: <%# DataBinder.Eval(Container.DataItem, "ISBN") %></b>
<ASP:Button CommandName="Update" Text="Update" runat="server" />
<ASP:Button CommandName="Delete" Text="Delete" runat="server" />
<ASP:Button CommandName="Cancel" Text="Cancel" runat="server" /><br />
Title:
<ASP:TextBox id="txtTitle" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
size="46" runat="server" /><br />
PublicationDate:
<ASP:TextBox id="txtPubDate" size="20" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "PublicationDate") %>'/>
</EditItemTemplate> </ASP:DataList></form><!---------------------------------------------------------------------------><script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindDataGrid(); // create data set and bind to list control
}
void DoItemSelect(Object objSource, DataListCommandEventArgs objArgs )
{
lblSQL.Text = ""; // clear any content from SQL statement Label // see if it was the Select button that was clicked
if (objArgs.CommandName == "Select")
{
// set the SelectedIndex property of the list to this item// s index
MyDataList.SelectedIndex = objArgs.Item.ItemIndex;
BindDataGrid(); // bind the data and display it
}
}
void DoItemEdit(Object objSource, DataListCommandEventArgs objArgs)
{
// set the SelectedIndex property of the list to -1 to "unselect" it
MyDataList.SelectedIndex = -1; // set the EditItemIndex property of the list to this item's index
MyDataList.EditItemIndex = objArgs.Item.ItemIndex;
BindDataGrid(); // bind the data and display it
}
void DoItemUpdate(Object objSource, DataListCommandEventArgs objArgs)
{
// get a reference to the title and publication date text boxes
TextBox objTitleCtrl = (TextBox)objArgs.Item.FindControl("txtTitle");
TextBox objPubDateCtrl = (TextBox)objArgs.Item.FindControl("txtPubDate");
// create a suitable SQL statement and execute it
string strSQL = "UPDATE Booklist SET Title='" + objTitleCtrl.Text + "', "
+ "PublicationDate='" + objPubDateCtrl.Text + "' "
+ "WHERE ISBN='" + MyDataList.DataKeys[objArgs.Item.ItemIndex] + "'";
ExecuteSQLStatement(strSQL); // set EditItemIndex property of grid to -1 to switch out of Edit mode
MyDataList.EditItemIndex = -1;
BindDataGrid(); // bind the data and display it
}
void DoItemDelete(Object objSource, DataListCommandEventArgs objArgs)
{
// create a suitable SQL statement and execute it
string strSQL = "DELETE FROM Booklist WHERE ISBN='"
+ MyDataList.DataKeys[objArgs.Item.ItemIndex] + "'";
ExecuteSQLStatement(strSQL); // set EditItemIndex property of grid to -1 to switch out of Edit mode
MyDataList.EditItemIndex = -1;
BindDataGrid(); // bind the data and display it
}
void DoItemCancel(Object objSource, DataListCommandEventArgs objArgs)
{
// set EditItemIndex property of grid to -1 to switch out of Edit mode
MyDataList.EditItemIndex = -1;
BindDataGrid(); // bind the data and display it
}
void ExecuteSQLStatement(string strSQL)
{
// this is where the SQL statement would be executed against the
// original data source. In this example, we're simply displaying
// the statement in a Label on the page
lblSQL.Text = "<b>The SQL statement that would be executed is:</b><br />" + strSQL;
}
void BindDataGrid()
{
// get connection string from ..\global\connect-strings.ascx user control
string strConnect = ctlConnectStrings.OLEDBConnectionString; // create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '%18610025%'"; // create a variable to hold an instance of a DataReader object
OleDbDataReader objDataReader; try
{
// create a new Connection object using the connection string
OleDbConnection objConnect = new OleDbConnection(strConnect); // open the connection to the database
objConnect.Open(); // create a new Command using the connection object and select statement
OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect); // execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader();
}
catch (Exception objError)
{
// display error details
outError.InnerHtml = "<b>* Error while accessing data</b>.<br />"
+ objError.Message + "<br />" + objError.Source + "<p />";
return; // and stop execution
} // set the DataSource property and bind the list
MyDataList.DataSource = objDataReader;
MyDataList.DataBind();
}</script><!--------------------------------------------------------------------------->
<hr /><span class="cite">[<a href="../global/viewsource.aspx">view source</a>]
+copy;2001 <a class="cite" href="http://www.wrox.com/">Wrox Press</a> -
<a class="cite" href="http://www.wrox.com/Books/Book_Details.asp?isbn=1861004885">Professional ASP.NET</a> (ISBN: 1-861004-88-5)</span>
</body>
</html>