[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.   

    e.CommandArgument
    <asp:Button ID="Button1" runat="server" OnClick="btn_Click" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "id" )%>' Text="Button" />
    这是一个办法。
      

  2.   

     //                                                                选中行显示整条数据
            private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
            {
                //获取行的name值,用来调用ID
                string name = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                this.BindDataByName("IDNO", name);
            }
      

  3.   

     for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            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);
                            }
                        }
      

  4.   

    增加一个id的隐藏列  用click事件去取相应的cell
      

  5.   

    <tr id = "trContent" onclick = "GetId(this);">
    <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给你看看吧
      

  6.   

    function IsChecked(cb)
    {
        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>&nbsp;</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)">&nbsp;</td><td onclick="javascript:dopost(0)">蘇州市太倉市白云渡路8號</td><td onclick="javascript:dopost(0)">&nbsp;</td><td onclick="javascript:dopost(0)">&nbsp;</td><td onclick="javascript:dopost(0)">&nbsp;</td><td onclick="javascript:dopost(0)">&nbsp;</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)">&nbsp;</td><td onclick="javascript:dopost(2)">qqq</td><td onclick="javascript:dopost(2)">&nbsp;</td><td onclick="javascript:dopost(2)">&nbsp;</td><td onclick="javascript:dopost(2)">&nbsp;</td><td onclick="javascript:dopost(2)">&nbsp;</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)">&nbsp;</td><td onclick="javascript:dopost(3)">312313</td><td onclick="javascript:dopost(3)">&nbsp;</td><td onclick="javascript:dopost(3)">&nbsp;</td><td onclick="javascript:dopost(3)">&nbsp;</td><td onclick="javascript:dopost(3)">0002</td>
    </tr>
    </table>怎么样?看出点规律来了???
      

  7.   

    回复1楼:我不行ID显示出来回复2楼:我的是DataList控件回复4楼:如何隐藏,如何获取?回复5楼,没看出什么规律来,我重没见过这样用JS的