[VS2005 Access数据库 C# .aspx]
图1:数据库
<asp:DataList ID="DataList1" runat="server" Height="1px" Width="100%" OnItemCommand="DataList1_ItemCommand"
CellPadding="4" CellSpacing="1" ForeColor="#333333" EnableViewState="False">
<ItemTemplate>
<table border="0" width="100%" style="font-size: 14px;">
<tr>
<td align="left">
<asp:LinkButton ID="linkNumber" runat="server" CommandName="SelectInfo" ForeColor="black">
<%# DataBinder.Eval(Container.DataItem, "Title")%>
</asp:LinkButton>
</td>
<td style="width: 100">
<%# DataBinder.Eval(Container.DataItem, "RDate","{0:yyyy-MM-dd}")%>
</td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:DataList> protected void Page_Load(object sender, EventArgs e)
{
DataList1.DataSource = clsSql.GetDs("select ID,Title,RDate from 表 Order By ID desc ", "表");
DataList1.DataBind();
} //查看详细新闻
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "SelectInfo")
{
//点击新闻标题后,如何得到ID ?
}
}
图2:目前效果图
图1是数据库字段,ID是string类型的;
不清楚我意思,请回帖;
图1:数据库
<asp:DataList ID="DataList1" runat="server" Height="1px" Width="100%" OnItemCommand="DataList1_ItemCommand"
CellPadding="4" CellSpacing="1" ForeColor="#333333" EnableViewState="False">
<ItemTemplate>
<table border="0" width="100%" style="font-size: 14px;">
<tr>
<td align="left">
<asp:LinkButton ID="linkNumber" runat="server" CommandName="SelectInfo" ForeColor="black">
<%# DataBinder.Eval(Container.DataItem, "Title")%>
</asp:LinkButton>
</td>
<td style="width: 100">
<%# DataBinder.Eval(Container.DataItem, "RDate","{0:yyyy-MM-dd}")%>
</td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:DataList> protected void Page_Load(object sender, EventArgs e)
{
DataList1.DataSource = clsSql.GetDs("select ID,Title,RDate from 表 Order By ID desc ", "表");
DataList1.DataBind();
} //查看详细新闻
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "SelectInfo")
{
//点击新闻标题后,如何得到ID ?
}
}
图2:目前效果图
图1是数据库字段,ID是string类型的;
不清楚我意思,请回帖;
解决方案 »
- 无刷新droplist联动代码,问题,高手们,急急急急急急急急急!!
- asp.net结合WMI的应用
- 新手提问!关于页面显示其它页面的问题!
- 【在线等高手回答】c#操作excel后,如何实现不保存,直接提供给客户端下载!采用的是(stream或者FileStream)的形式。
- 我想好好学习一下Css不知道哪本书好,麻烦过来人推荐一本~~
- 求条sql语句你 『SOS』
- asp.net中连接数据库
- 寻成熟解决方案,,用户要求由他们自己在后台随意调整栏目排列顺序,这个要怎么做最好??
- 高分求WEB接收传真问题
- ASP.NET数据库入门经典 -C#编程篇源代码
- ADO.NET 连接数据库
- 大家进来讨论一下这个系统
<asp:Button ID="Button1" runat="server" OnClick="btn_Click" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "id" )%>' Text="Button" />
这是一个办法。
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
//获取行的name值,用来调用ID
string name = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
this.BindDataByName("IDNO", name);
}
{
if (dataGridView1.Rows[i].Selected == true)
{
string name = this.dataGridView1.Rows[i].Cells[1].Value.ToString();//身份证号
string delete = "delete from StuTable where [IDNO]='" + name + "'";
constring(delete);
}
}
<td align="left">
<asp:TextBox ID = "txtId" ruant = "server" text = " <%# DataBinder.Eval(Container.DataItem, "ID")%>
"
<asp:LinkButton ID="linkNumber" runat="server" CommandName="SelectInfo" ForeColor="black">
<%# DataBinder.Eval(Container.DataItem, "Title")%></asp:LinkButton>
</td>
<td style="width: 100">
<%# DataBinder.Eval(Container.DataItem, "RDate","{0:yyyy-MM-dd}")%>
</td>
</tr>通过上面的方法可以得到选中的<tr>的ID那么在JS事件GetID里面就能根据这个ID去推断出新填加进去的textBox的ID,然后就能拿到你想要的值了像DataList GridView等生成的源码的ID都是有规律的,我拿一个我自己写的简单JS给你看看吧
{
var count = document.getElementById("hfCount").value;
for(i = 2;i<count + 1;i++)
{
var cbo;
if(i<10)
{
cbo = document.getElementById("gvArea_ctl0"+i+"_cboIndex");
}
else
{
cbo = document.getElementById("gvArea_ctl"+i+"_cboIndex");
}
if(cbo != cb)
{
cbo.checked = false;
}
else
{
cbo.checked = true;
}
}
}规律怎么看出来的? 打开你的网页后,右键 查看源码,下面是我的程序的某页面的部分源码:<table class="repeater " cellspacing="0" rules="all" border="1" id="gvAddCustomer" style="font-size:12px;width:900px;border-collapse:collapse;">
<tr class="GridViewthead " style="color:Black;">
<td> </td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$CustId')" style="color:Black;">客戶代碼</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$ChineseName')" style="color:Black;">中文名稱</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$ForeignName')" style="color:Black;">英文名稱</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$InvoiceAddr')" style="color:Black;">發票地址</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$Fax')" style="color:Black;">Fax</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$ContactName')" style="color:Black;">連絡人</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$ContactPhone')" style="color:Black;">連絡人電話</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$ContactEmail')" style="color:Black;">連絡人Email</a></td><td><a href="javascript:__doPostBack('gvAddCustomer','Sort$SalesId')" style="color:Black;">業務員</a></td>
</tr><tr onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#bdddfc'" onmouseout="this.style.backgroundColor=c">
<td>
<input id="gvAddCustomer_ctl02_CheckBox1" type="checkbox" name="gvAddCustomer$ctl02$CheckBox1" onclick="IsChecked(this);" />
</td><td onclick="javascript:dopost(0)">C0001</td><td onclick="javascript:dopost(0)">Well International e.K</td><td onclick="javascript:dopost(0)"> </td><td onclick="javascript:dopost(0)">蘇州市太倉市白云渡路8號</td><td onclick="javascript:dopost(0)"> </td><td onclick="javascript:dopost(0)"> </td><td onclick="javascript:dopost(0)"> </td><td onclick="javascript:dopost(0)"> </td><td onclick="javascript:dopost(0)">0001</td>
</tr><tr onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#bdddfc'" onmouseout="this.style.backgroundColor=c" style="background-color:#DAECFE;">
<td>
<input id="gvAddCustomer_ctl03_CheckBox1" type="checkbox" name="gvAddCustomer$ctl03$CheckBox1" onclick="IsChecked(this);" />
</td><td onclick="javascript:dopost(1)">C0002</td><td onclick="javascript:dopost(1)">925 Limited</td><td onclick="javascript:dopost(1)">Limited</td><td onclick="javascript:dopost(1)">蘇州市太倉市白雲渡路5號</td><td onclick="javascript:dopost(1)">86-512-53458812</td><td onclick="javascript:dopost(1)">SKY</td><td onclick="javascript:dopost(1)">86-512-53458812</td><td onclick="javascript:dopost(1)">[email protected]</td><td onclick="javascript:dopost(1)">0001</td>
</tr><tr onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#bdddfc'" onmouseout="this.style.backgroundColor=c">
<td>
<input id="gvAddCustomer_ctl04_CheckBox1" type="checkbox" name="gvAddCustomer$ctl04$CheckBox1" onclick="IsChecked(this);" />
</td><td onclick="javascript:dopost(2)">C0003</td><td onclick="javascript:dopost(2)">VALENTI S.R.L.</td><td onclick="javascript:dopost(2)"> </td><td onclick="javascript:dopost(2)">qqq</td><td onclick="javascript:dopost(2)"> </td><td onclick="javascript:dopost(2)"> </td><td onclick="javascript:dopost(2)"> </td><td onclick="javascript:dopost(2)"> </td><td onclick="javascript:dopost(2)">0001</td>
</tr><tr onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#bdddfc'" onmouseout="this.style.backgroundColor=c" style="background-color:#DAECFE;">
<td>
<input id="gvAddCustomer_ctl05_CheckBox1" type="checkbox" name="gvAddCustomer$ctl05$CheckBox1" onclick="IsChecked(this);" />
</td><td onclick="javascript:dopost(3)">C0004</td><td onclick="javascript:dopost(3)">测试</td><td onclick="javascript:dopost(3)">Test</td><td onclick="javascript:dopost(3)"> </td><td onclick="javascript:dopost(3)">312313</td><td onclick="javascript:dopost(3)"> </td><td onclick="javascript:dopost(3)"> </td><td onclick="javascript:dopost(3)"> </td><td onclick="javascript:dopost(3)">0002</td>
</tr>
</table>怎么样?看出点规律来了???