请大家指点下!
我现在在Datalist的模板列中使用一个HTML的按钮,通过这个按钮调用脚本往数据库中插入数据。现在我不知道如何获取当前记录行的索引ID。因为我这里需要根据索引ID来插入数据。
aspx页面
<script language= "javascript " type= "text/javascript ">
<!--
function yy()
{
var BlogName= document.getElementById( "Text4 ").value;
var BlogHtml= document.getElementById( "Text5 ").value;
var BolgSignature= document.getElementById( "Text6 ").value;
var AssociatorID= document.getElementById( "Text7 ").value;
var ChickNumber= document.getElementById( "Text1 ").value;
alert(BlogTest.TestSql(BlogName,BlogHtml,BolgSignature,AssociatorID,ChickNumber).value);
}
function tt(obj)
{
var a1=obj.nextSibling.nextSibling;
if(a1.style.display == "none ")
a1.style.display= "block ";
else
a1.style.display = "none ";
}
<asp:DataList ID= "DataList1 " runat= "server " DataKeyField= "BlogID " OnSelectedIndexChanged= "DataList1_SelectedIndexChanged ">
<ItemTemplate>
<hr size = "1 " />
<asp:TextBox ID= "text " runat= "server " Text= ' <%# Eval( "DiaryContents ") %> ' TextMode= "MultiLine " Width= "225px "> </asp:TextBox>
浏览数: <asp:Label ID= "Label8 " runat= "server " Text= ' <%# Eval( "ChickNumber ") %> ' />
回复数: <asp:Label ID= "Label10 " runat= "server " Text= ' <%# Eval( "CommentNumber ") %> '/> <br />
发表日期: <asp:Label ID= "Label9 " runat= "server " Text= ' <%# Eval( "DiaryDate ") %> '/>
<input id= "Button2 " type= "button " onclick= "tt(this) " value= "button " /> <br />
<table id= "t " style= "display:none ">
<tr>
<td style= "width: 100px ">
博客名称 </td>
<td style= "width: 100px ">
<td style= "width: 100px ">
<input id= "Text4 " type= "text " /> </td>
</tr>
<tr>
<td style= "width: 100px ">
博客路径 </td>
<td style= "width: 100px ">
<td style= "width: 100px ">
<input id= "Text5 " type= "text " /> </td>
</tr>
<tr>
<td style= "width: 100px ">
博客签名 </td>
<td style= "width: 100px ">
<td style= "width: 100px ">
<input id= "Text6 " type= "text " /> </td>
</tr>
<tr>
<td style= "width: 100px ">
用户ID </td>
<td style= "width: 100px ">
<td style= "width: 100px ">
<input id= "Text7 " type= "text " /> </td>
</tr>
<tr>
<td style= "width: 100px ">
访问量 </td>
<td style= "width: 100px ">
<td style= "width: 100px ">
<input id= "Text1 " type= "text " /> </td>
</tr>
<tr>
<input id= "Button3 " onclick= "yy() " type= "button " value= "提交 " />
</tr>
</table>
</ItemTemplate>
</asp:DataList>
CS代码
BLL bll = new BLL();
int DataListcount = 0;
AjaxPro.Utility.RegisterTypeForAjax(typeof(BlogTest));
[AjaxPro.AjaxMethod]
public string TestSql(string BlogName, string BlogHtml, string BolgSignature, string AssociatorID, string ChickNumber)
{
int AssociatorIDa = int.Parse(AssociatorID);
string test = bll.insertComment(DataListcount, AssociatorIDa, BlogName, DateTime.Now);
return test;
}
现在就是如何在 TestSql方法中获取到Datalist当前选中行的索引
请大家帮忙指点下!谢谢了!
[解决办法]
最笨的办法:
<input id= "Button2 " type= "button " onclick= "tt(this, ' <%# Eval( "BlogID ")%> ') " value= "button " />