C# 创建一个表,在表中插入两列,每循环一次插入一行
发布网友
发布时间:2022-10-01 17:08
我来回答
共5个回答
热心网友
时间:2024-09-05 16:56
首先是网页源码:
<asp:DataList runat="server" Width="100%" ID="dsDanshen">
<HeaderTemplate>
<table style="border: 0pt groove #FFFFFF; background-color:#F5FAFE; " width="100%" cellspacing="0" cellpadding="0" frame="border" border="0">
<span class="style3">单身男女交流区</span>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan="2" style="color: #FFFFFF; font-size: small; background-color: #2F589C; height: 30px;">发表于:<%# DataBinder.Eval(Container.DataItem,"timee") %>
</td>
</tr>
<tr>
<td style="border-width: 1pt; border-color: #2F589C; border-left-style: solid; border-top-style: solid;" align="center">
</td>
<td rowspan="3" style="border-style: solid; border-width: 1pt; border-color: #2F589C; height: 300px; font-size: small; width: 80%;" align="left" valign="baseline"><%# DataBinder.Eval(Container.DataItem,"content") %>
</td>
</tr>
<tr>
<td style="border-width: 1pt; border-color: #2F589C; width: 20%; height: 130px; border-left-style: solid; font-size: small; color: #00FF00;" align="center"><asp:Image runat="server" ID="im1" Width="80px" Height="100px" ImageUrl="touxiang/女1.jpg" /><br />ID:<%# DataBinder.Eval(Container.DataItem,"username") %>
</td>
</tr>
<tr>
<td style="border-color: #2F589C; border-left-style: solid; border-bottom-style: solid; border-bottom-width: 1pt; border-left-width: 1pt; font-size: small; color: #808000;" align="center" valign="baseline">所属社区:<%# DataBinder.Eval(Container.DataItem,"nname") %>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: #FFFFFF; height: 10px; width: 100%">
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
再是CS源码:
protected void Page_Load(object sender, EventArgs e)
{
if (!(bool)Application["login"])
{
Response.Redirect("Denglu.aspx");
}
else
{
pages();
}
}
public void pages()
{
int curpage = Convert.ToInt32(this.Label2.Text);
SqlConnection con = db.createCon();
SqlDataAdapter sdr = new SqlDataAdapter();
sdr.SelectCommand = new SqlCommand("select * from zhubiao where nid=1 and lid=1 order by(iid) desc", con);
DataSet ds = new DataSet();
sdr.Fill(ds, "tem");
//DataView dv = ds.Tables["tem"].DefaultView;
//PagedDataSource ps = new PagedDataSource;
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["tem"].DefaultView;
ps.AllowPaging=true;
ps.PageSize =10;
ps.CurrentPageIndex = curpage - 1;
//pagecount = ps.PageCount;
if (curpage == 1)
{
this.first.Enabled = false;
this.previous.Enabled = false;
this.next.Enabled = true;
this.last.Enabled = true;
}
if (curpage == ps.PageCount)
{
this.first.Enabled = true;
this.previous.Enabled = true;
this.next.Enabled = false;
this.last.Enabled = false;
}
if (curpage == 1 && curpage == ps.PageCount)
{
this.first.Enabled = false;
this.previous.Enabled = false;
this.next.Enabled = false;
this.last.Enabled = false;
}
//this.dsDanshen.DataSource = ps;//ds.Tables["tem"]; //
//this.dsDanshen.DataBind();
this.dsDanshen.DataSource = ps;
this.dsDanshen.DataBind();
}
热心网友
时间:2024-09-05 16:57
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("name");
DataRow row;
for(int i=0;i<5;i++)
{
row = dt.NewRow();
row[0] = i;
row[1] = "name-"+ i.ToString();
dt.Rows.Add(row);
}
热心网友
时间:2024-09-05 16:57
你这种方法来实现功能太过于繁琐了,而且容易出错,功能也不够强大,要是你要的话你最好建个数据库来,设好数据库的字段,用datagridview查看。你要怎么样就怎么样。
热心网友
时间:2024-09-05 16:58
你说的是可视化的吧
在窗体中添加“listview”控件
然后在相应的button事件中添加代码
{
listviewitem listitem=new listviewitem();
listitem = new ListViewItem(A .ToString(),0); listitem.SubItems.Add(B.ToString());
listview1.items.add(listitem)
}
A和B分别为你添加进去的东西
至于列名,你可以在控件的属性中的Cloumn属性的 collection中预先输入
大小写不一定正确。。我凭记忆写的
热心网友
时间:2024-09-05 16:58
DataTable dt = new DataTable();
dt.Columns.Add("matID", typeof(string));
dt.Columns.Add("matName", typeof(string));
DataRow dr = dt.NewRow();
dr[0] = "asd";
dr[1] = "haha";
dt.Rows.Add(dr);