Hello LehrSJ,
In ASP.NET web page, the server control's ID will vary from their actual
client id(of the html element) when render to client browser. Therefore,
when we want to inject some script code which will manipulate the ASP.NET
webcontrol's client-side element, we should use the "ClientID" property of
the control, also this property is only useful after the control has been
added into a parent control collection in the page's control tree. A
general way to view an ASP.NET page's control tree is turn on the trace on
page through the @page directive, like:
<%@ Page Trace="true" ....................... %>
For your scenario, are you using TemplateField for the column you put the
checkbox and TextBox which need to interact with each other on client-side?
If not, I would suggest you use TemplateField so that we can have more
flexible control over those controls. For example:
=======================
<asp
etailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="id"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
AllowPaging="True" OnItemCreated="DetailsView1_ItemCreated">
<Fields>
....................................
<asp:TemplateField HeaderText="Operate">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="name:
"></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%#
Eval("name") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp
etailsView>
============================================
And we can define some client scripts which accept control's ClientID as
parameter and manipulate them. e.g
==============================
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function chk_onchange(chkid, txtid)
{
var chk = document.getElementById(chkid);
var txt = document.getElementById(txtid);
txt.value = chk.checked;
}
</script>
===============================
In code behind, we can use the DetailsView control's "ItemCreated" event to
bind script function to control's attributes as below:
===============================
protected void DetailsView1_ItemCreated(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
CheckBox chk = DetailsView1.FindControl("CheckBox1") as
CheckBox;
TextBox txt = DetailsView1.FindControl("TextBox1") as TextBox;
chk.Attributes["onclick"] = string.Format("chk_onchange( '{0}',
'{1}');", chk.ClientID, txt.ClientID);
}
}
============================
Hope this helps some. If you have anything unclear or any further questions
on this, please feel free to let me know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.