【发布时间】:2015-08-14 15:45:19
【问题描述】:
我有一个 ASP.NET Web 窗体页面,我有一个字段,我从 SQL Server 数据库加载一些数据。 我还通过这种方式向该字段添加了一个 Checkbox 控件:
if (!e.Row.Cells[8].Text.Equals("---"))
{
CheckBox chkbox = new CheckBox();
chkbox.ID = "SelectedTel8_" + e.Row.Cells[1].Text;
chkbox.Text = e.Row.Cells[8].Text;
e.Row.Cells[8].Controls.Add(chkbox);
chkbox.Attributes.Add("OnClick", "javascript:selectCheckBox(this);");
chkbox = null;
}
if (!e.Row.Cells[9].Text.Equals("---"))
{
CheckBox chkbox = new CheckBox();
chkbox.ID = "SelectedTel9_" + e.Row.Cells[1].Text;
chkbox.Text = e.Row.Cells[9].Text;
e.Row.Cells[9].Controls.Add(chkbox);
chkbox.Attributes.Add("OnClick", "javascript:selectCheckBox(this);");
chkbox = null;
}
if (!e.Row.Cells[10].Text.Equals("---"))
{
CheckBox chkbox = new CheckBox();
chkbox.ID = "SelectedTel10_" + e.Row.Cells[1].Text;
chkbox.Text = e.Row.Cells[10].Text;
e.Row.Cells[10].Controls.Add(chkbox);
chkbox.Attributes.Add("OnClick", "javascript:selectCheckBox(this);");
chkbox = null;
}
在这个页面上,我还创建了一个按钮行:
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="ButtonSendSMS" runat="server" Text="EnviarSms" CommandName="EnviarSms1" OnClientClick="javascript:SendSmsTel(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
它调用一个名为“SendSmsTel”的javascript函数。
我需要做的是:
每当用户单击按钮时,我都需要从该行的其他字段中检索信息以在其他操作中使用它。
问题是我找不到访问该行元素的方法。当我在给定行上有控件时,我对它们进行了标识,然后我可以使用
window.document.getElementById()
但是没有控件的数据字段呢?
[link]我尝试了很多东西,但都没有奏效。不知道我做错了什么: [链接]How to access gridview cell value with javascript [链接]How to get Column Value for a given Row within GridView using javascript in asp.net? [链接]Why is Container.DataItem being passed as a string literal?
如何访问单击按钮所在行的内容? 如果可以,请教我 C# 和 JavaScript。 谢谢。
【问题讨论】:
-
你到底想在这里完成什么?
-
使用 jquery 你可以做类似
$('row_id_here').find('input[type=checkbox]');的事情。您也可以在没有 jquery 的情况下做到这一点,但需要做更多的工作。这种方法有问题吗? -
我还是不知道怎么用JQuery,我不知道我可以用它来做到这一点。
-
应用程序很简单,我在 gridView 中有一个数据列表(姓名和 3 个电话)。每行都有一个按钮。用户选择其中一部电话,然后单击该行上的按钮,然后触发事件以向所选电话发送短信。然后它必须在另一个数据库表中插入该消息的日志。这很简单!当我单击按钮时,我只是想不出一种从整个列中获取数据的方法。
标签: javascript c# asp.net gridview webforms