Datagrid edit question

L

Leo

I have a datagrid with the first column as a Edit,Update,Cancel button
column. The other 5 columns are template columns. When I click the Edit
button in IE6 the row correctly displays the controls defined in the
<EditItemTemplate> however when I right click and do a view source I cannot
find any of the input textboxes in the source. I have used the
ItemDatabound event to try to attach javascript to the textboxes and in
debug mode while stepping through it seems to find the controls and add the
attributes but they never show up in the view source. Here is the source
line for just the datarow that is in the edit mode:

<tr style="color:Black;background-color:#EEEEEE;">
<td style="color:Blue;">
<a href="javascript:__doPostBack('grdStaff$_ctl4$_ctl0','')"
style="color:Blue;">Edit</a>
</td>
<td>
<span>Beck, John</span>
</td>
<td>
<span id="grdStaff__ctl4_lblLoginName">BeckJ</span>
</td>
<td>
<span id="grdStaff__ctl4_lblPassword">1235</span>
</td>
<td>
<span id="grdStaff__ctl4_lblEmail">[email protected]</span>
</td>
<td align="Center">
<font face="Wingdings"><b></b></font>
</td>
</tr>

It looks like it is still showing the Edit button even though the row is
displayed in the edit mode in IE. I have done a find in the source for
"BeckJ" and this one row is the only place it is found which is the line
being edited. How is IE displaying the textboxes and is it possible to
attach javascript to them?
 
G

Guest

Hi Leo,

Look at Page.RegisterClientScriptBlock for information on how to attach
JavaScript to .NET server controls. If you want to get to the controls on the
server side, you will need to name the textboxes appropriately and use the
"FindControl" method to get to them.

Hope this helps.
Tony.
 
L

Leo

I have already built a scripting.cs class that does this. I have used it to
attach the javascript to controls on pages but I can't get it to work with
this datagrid. As you can see I have named all my controls and I can find
them in the datagrid.itemdatabound event. I can even add the attributes
with Control.Attributes.Add("onmouseover", "javascript"), they just never
show up in the IE view source and never do anything. I tried building a
simple project with just a one row datagrid with an edit column and when it
is in edit mode in IE the <input> controls show up fine, they just don't in
this datagrid.

Here is a snippet of the HTML view of the .aspx:
<asp:TemplateColumn
HeaderText="Login">
<ItemTemplate>
<asp:Label
ID="lblLoginName"
runat="server"
Text='<%# DataBinder.Eval(Container.dataitem, "LoginName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
ID="txtLoginName"
runat="server"
width="95%"
Text='<%# DataBinder.Eval(Container.dataitem, "LoginName") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn
HeaderText="Password">
<ItemTemplate>
<asp:Label
ID="lblPassword"
runat="server"
Text='<%# DataBinder.Eval(Container.dataitem, "LoginPassword") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
ID="txtPassword"
runat="server"
width="95%"
Text='<%# DataBinder.Eval(Container.dataitem, "LoginPassword") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
 
G

Guest

I have attached the Javascript to the controls on the Page_Load event and it
works for me. Are you doing the same?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top