@@@@@@关于datalist的排版与事件@@@@@@@@@@@@@@

fornothing 2004-10-21 04:32:48
我想通过一个按钮弹出一个小的窗口,在窗口里面显示三个表的数据,遇到了如下问题:

1、窗口我已经可以弹出,可是大小固定,不能满足三个datalist的要求
2、因为datalist的数据是不固定的,所以三个datalist不知道应当如何排版,以避免会覆盖 或 比较难看
3、在datalist里面设立linkbutton,如果我想出现编辑效果,如何作。
http://chs.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/DataList/VB/DataList3.aspx
就像这个,可是找不到源码 谢谢

分不够可以再加~~~~~~~~

...全文
141 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
goody9807 2004-10-23
  • 打赏
  • 举报
回复
5.1、DataGridItem
每一个DataGridItem就是DataGrid中显示的一行,其中包括:
Header DataGrid 控件的标题部分
Item DataGrid 控件中的项
AlternatingItem DataGrid 控件中的交替项
SelectedItem DataGrid 控件中的选定项(由SelectedIndex设置,通过SelectedItem属性或者Items[SelectedIndex]来读取)
EditItem DataGrid 控件中处于编辑状态的项(由EditItemIndex设置,通过Items[EditItemIndex]来读取)
Separator DataGrid 控件中项之间的分隔符
Footer DataGrid 控件的脚注部分
Pager DataGrid 控件的页选择节
goody9807 2004-10-23
  • 打赏
  • 举报
回复
<table id="DataList1" cellspacing="0" cellpadding="3" rules="all" bordercolor="Black" border="1" style="border-color:Black;border-width:1px;border-style:solid;font-family:Verdana;font-size:8pt;width:150px;border-collapse:collapse;">
<tr>
<td style="background-color:#AAAADD;">

</td>
</tr><tr>
<td>
<a id="DataList1__ctl1_button1" href="javascript:__doPostBack('DataList1:_ctl1:button1','')">显示详细信息</a>
项 1
</td>
</tr><tr>
<td style="background-color:Yellow;">
项:
项 2
<br>
订购日期:
10/22/2004
<br>
数量:
2.0
<br>
</td>
</tr><tr>
<td>
<a id="DataList1__ctl3_button1" href="javascript:__doPostBack('DataList1:_ctl3:button1','')">显示详细信息</a>
项 3
</td>
</tr><tr>
<td style="background-color:Gainsboro;">
<a id="DataList1__ctl4_button1" href="javascript:__doPostBack('DataList1:_ctl4:button1','')">显示详细信息</a>
项 4
</td>
</tr><tr>
<td>
<a id="DataList1__ctl5_button1" href="javascript:__doPostBack('DataList1:_ctl5:button1','')">显示详细信息</a>
项 5
</td>
</tr><tr>
<td style="background-color:Gainsboro;">
<a id="DataList1__ctl6_button1" href="javascript:__doPostBack('DataList1:_ctl6:button1','')">显示详细信息</a>
项 6
</td>
</tr><tr>
<td>
<a id="DataList1__ctl7_button1" href="javascript:__doPostBack('DataList1:_ctl7:button1','')">显示详细信息</a>
项 7
</td>
</tr><tr>
<td style="background-color:Gainsboro;">
<a id="DataList1__ctl8_button1" href="javascript:__doPostBack('DataList1:_ctl8:button1','')">显示详细信息</a>
项 8
</td>
</tr><tr>
<td>
<a id="DataList1__ctl9_button1" href="javascript:__doPostBack('DataList1:_ctl9:button1','')">显示详细信息</a>
项 9
</td>
</tr>
</table>
fornothing 2004-10-23
  • 打赏
  • 举报
回复
大部分都搞定了 ~~~~~~~`谢谢~~~~~~

还有这个帮个忙
http://chs.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/DataList/VB/DataList2.aspx

这个样式的,我对selectItemTemplate的数据绑定了label,可是每次出来都是EditItemTemplate的情况
happyjun2000 2004-10-23
  • 打赏
  • 举报
回复
顶,接点分^_^
无聊就接分来了
tavor 2004-10-21
  • 打赏
  • 举报
回复
an exmaple of mine using datalist to show、edit、cancel、update data.
------------------------------------
EditExample.aspx
------------------------------------
<%@ Page language="c#" Codebehind="EditExample.aspx.cs" AutoEventWireup="false" Inherits="MyTest.EditExample" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>EditExample</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体" size="-2">
<asp:DataList id="DataList1" runat="server" Width="560" Height="176" HorizontalAlign="Center">
<HeaderTemplate>
<table width="100%" bgcolor="#cc9966">
<tr>
<td width="25%">操作</td>
<td width="25%">用户ID</td>
<td width="25%">姓名</td>
<td width="25%">邮编</td>
</tr>
</table>
</HeaderTemplate>
<FooterTemplate>
<table width="100%" bgcolor="#ffcc00" cellpadding="0" cellspacing="0">
<tr>
<td align="center">CopyRight@Tavor 2004</td>
</tr>
</table>
</FooterTemplate>
<ItemTemplate>
<TABLE width="100%" bgColor="#336699">
<TR>
<TD width="25%">
<asp:LinkButton id="LinkButton1" runat="server" CommandName="Edit">编辑</asp:LinkButton></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.au_id") %></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.au_lname") %></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.zip") %></TD>
</TR>
</TABLE>
</ItemTemplate>
<AlternatingItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" width="100%">
<TR>
<TD width="25%">
<asp:LinkButton id="Linkbutton2" runat="server" CommandName="Edit">编辑</asp:LinkButton></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.au_id") %></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.au_lname") %></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.zip") %></TD>
</TR>
</TABLE>
</AlternatingItemTemplate>
<EditItemTemplate>
<TABLE width="100%" bgColor="#339900">
<TR>
<TD width="25%">
<asp:LinkButton id="Linkbutton3" runat="server" CommandName="Cancel">取消</asp:LinkButton>
<asp:LinkButton id="Linkbutton4" runat="server" CommandName="Update">更新</asp:LinkButton></TD>
<TD width="25%"><%# DataBinder.Eval(Container,"DataItem.au_id") %></TD>
<TD width="25%">
<asp:TextBox id=TextBox1 runat="server" Width="88px" Text='<%# DataBinder.Eval(Container,"DataItem.au_lname") %>'>
</asp:TextBox></TD>
<TD width="25%">
<asp:TextBox id=Textbox2 runat="server" Width="88px" Text='<%# DataBinder.Eval(Container,"DataItem.zip") %>'>
</asp:TextBox></TD>
</TR>
</TABLE>
</EditItemTemplate>
</asp:DataList></FONT>
</form>
</body>
</HTML>
------------------------------------
EditExample.aspx.cs
------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace MyTest
{
/// <summary>
/// EditExample 的摘要说明。
/// </summary>
public class EditExample : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DataList1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
this.BindList();
}
}
private void BindList()
{
SqlConnection sc=new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=yourpass;");
SqlDataAdapter sda=new SqlDataAdapter("select au_id,au_lname,zip from authors",sc);
DataSet ds=new DataSet();
sda.Fill(ds,"authors");
ds.Tables[0].DefaultView.Sort="zip asc,au_lname desc";
this.DataList1.DataSource=ds.Tables[0].DefaultView;
this.DataList1.DataKeyField="au_id";
this.DataList1.DataBind();
sc.Close();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataList1.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DataList1_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex=e.Item.ItemIndex;
this.BindList();
}
private void DataList1_CancelCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
this.DataList1.EditItemIndex=-1;
this.BindList();
}
private void DataList1_UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
//you should update operation yourself
Response.Write("you should write update operation yourself!");
this.DataList1.EditItemIndex=-1;
this.BindList();
}


private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
switch(e.CommandName)
{
case "Edit":
this.DataList1_EditCommand(source,e);
break;
case "Update":
this.DataList1_UpdateCommand(source,e);
break;
default:
this.DataList1_CancelCommand(source,e);
break;
}
}
}
}

asuntea 2004-10-21
  • 打赏
  • 举报
回复
up
cancersyf 2004-10-21
  • 打赏
  • 举报
回复
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<html>
<head>
<script runat="server">
DataTable Cart = new DataTable();
DataView CartView;

void Page_Load(Object sender, EventArgs e)
{
GetSource();

if (!IsPostBack)
{
BindList();
}
}

void BindList()
{
ItemsList.DataSource = CartView;
ItemsList.DataBind();
}

void GetSource()
{

if (Session["ShoppingCart"] == null)
{

DataRow dr;

Cart.Columns.Add(new DataColumn("Qty", typeof(Int32)));
Cart.Columns.Add(new DataColumn("Item", typeof(String)));
Cart.Columns.Add(new DataColumn("Price", typeof(Double)));

Session["ShoppingCart"] = Cart;

for (int i = 1; i <= 9; i++)
{
dr = Cart.NewRow();
if (i % 2 != 0)
{
dr[0] = 2;
}
else
{
dr[0] = 1;
}
dr[1] = "Item " + i.ToString();
dr[2] = (1.23 * (i + 1));
Cart.Rows.Add(dr);
}
}
else
{
Cart = (DataTable)Session["ShoppingCart"];
}

CartView = new DataView(Cart);
CartView.Sort="Item";

return;
}

void Edit_Command(Object sender, DataListCommandEventArgs e)
{
ItemsList.EditItemIndex = e.Item.ItemIndex;
BindList();
}

void Cancel_Command(Object sender, DataListCommandEventArgs e)
{
ItemsList.EditItemIndex = -1;
BindList();
}

void Delete_Command(Object sender, DataListCommandEventArgs e)
{
String item = ((Label)e.Item.FindControl("ItemLabel")).Text;

CartView.RowFilter = "Item='" + item + "'";
if (CartView.Count > 0)
{
CartView.Delete(0);
}
CartView.RowFilter = "";

ItemsList.EditItemIndex = -1;
BindList();
}

void Update_Command(Object sender, DataListCommandEventArgs e)
{
String item = ((Label)e.Item.FindControl("ItemLabel")).Text;
String qty = ((TextBox)e.Item.FindControl("QtyTextBox")).Text;
String price = ((TextBox)e.Item.FindControl("PriceTextBox")).Text;

CartView.RowFilter = "Item='" + item + "'";
if (CartView.Count > 0)
{
CartView.Delete(0);
}
CartView.RowFilter = "";

DataRow dr = Cart.NewRow();
dr[0] = qty;
dr[1] = item;
if(price[0] == '$')
{
dr[2] = Convert.ToDouble(price.Substring(1));
}
else
{
dr[2] = Convert.ToDouble(price);
}
Cart.Rows.Add(dr);

ItemsList.EditItemIndex = -1;
BindList();
}

</script>
</head>
<body>
<form runat=server>
<h3>DataList Edit Example</h3>
Click <b>Edit</b> to edit the values of the item.
<br><br>
<asp:DataList id="ItemsList"
GridLines="Both"
RepeatColumns="3"
RepeatDirection="Horizontal"
CellPadding="3"
CellSpacing="0"
OnEditCommand="Edit_Command"
OnUpdateCommand="Update_Command"
OnDeleteCommand="Delete_Command"
OnCancelCommand="Cancel_Command"
runat="server">
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle>
<EditItemStyle BackColor="yellow">
</EditItemStyle>
<HeaderTemplate>
Items
</HeaderTemplate>
<ItemTemplate>
Item:
<%# DataBinder.Eval(Container.DataItem, "Item") %>
<br>
Quantity:
<%# DataBinder.Eval(Container.DataItem, "Qty") %>
<br>
Price:
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
<br>
<asp:LinkButton id="EditButton"
Text="Edit"
CommandName="Edit"
runat="server"/>
</ItemTemplate>
<EditItemTemplate>
Item:
<asp:Label id="ItemLabel"
Text='<%# DataBinder.Eval(Container.DataItem, "Item") %>'
runat="server"/>
<br>
Quantity:
<asp:TextBox id="QtyTextBox"
Text='<%# DataBinder.Eval(Container.DataItem, "Qty") %>'
runat="server"/>
<br>
Price:
<asp:TextBox id="PriceTextBox"
Text='<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>'
runat="server"/>
<br>
<asp:LinkButton id="UpdateButton"
Text="Update"
CommandName="Update"
runat="server"/>
<asp:LinkButton id="DeleteButton"
Text="Delete"
CommandName="Delete"
runat="server"/>
<asp:LinkButton id="CancelButton"
Text="Cancel"
CommandName="Cancel"
runat="server"/>
</EditItemTemplate>
</asp:DataList>
</form>
</body>
</html>
cancersyf 2004-10-21
  • 打赏
  • 举报
回复
你可以在弹出窗口中使用三个div,div的高度都是固定的,然后把datalist放在div中,当数据多的时候出现滚动条。
zpisgod 2004-10-21
  • 打赏
  • 举报
回复
1.那就不要固定大小了;
2.使用流式布局,不要用vs默认的网格布局,在页面属性中可以设置;
3.在datagrid的属性设置中添加编辑列,写相应的代码
tavor 2004-10-21
  • 打赏
  • 举报
回复
1.别设置窗口大小,或者根据数据的多少来设定,或者设置固定大小让datalist分页
2.把datalist的style属性都去掉,不要指定其绝对位置
3.分别设置你的itemtemplate和edittemplate,并给相应的控件设置editCommand和cancelCommand和updateCommand绑定就可以了。

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧