1

I want the stored value in "val" and assgined to the textbox in the gridview. I'm able to loop and find the rows but not the control. I'm getting a undefined error message. What I'm missing that I cannot find the control . Attached is the sample code:

<!--Javascript Code-->


<script type="text/javascript">
function SetPIN(val)
{
 if (Searching == 'eID')
{

  var num = val;
  var grdvw = document.getElementById('gvEvents');


for (var rowId = 1; rowId < grdvw.rows.length -1; rowId++){
var txtbx = grdvw.getElementById('txtEvtTo').value;

txtbx = num;


 }end for

 }
 }

</script>
  <asp:GridView ID:gvEvents runat="server" AutoGenerateColumns="False" >
  <Columns>
 <asp:TemplateField>
    <ItemTemplate>
 <asp:TextBox ID="txtEvtTo" runat="server" Width="250px"></asp:TextBox>
</ItemTemplate>
 </asp:TemplateField>
 </Columns>
 </asp:GridView>

I've tried different options that I've online but I haven't been able to get the value to textbox

Any suggestions would be greatly appreciate it.

DR

1 Answer 1

2

Don't look at the html markup in the IDE, but the rendered html as shown in "view page source" of your browser. asp control id's get mangled when rendered, so unless you set the control's ClientIDMode to Static, your call to getElementById won't work for finding the gridview or the cell controls.

Here are a couple of sample data rows from one of my gridviews:

<tr class="gvRowStyleContactList " valign="middle">
    <td>
        <span id="ctl00_ctl00_cphMain_IEHContent_gvEscalationContactListView_ctl02_lblEmailAddress">[email protected]</span>
    </td>
</tr>
<tr class="gvRowStyleContactList " valign="middle">
    <td>
        <span id="ctl00_ctl00_cphMain_IEHContent_gvEscalationContactListView_ctl03_lblEmailAddress">[email protected]</span>
    </td>
</tr>
Sign up to request clarification or add additional context in comments.

1 Comment

I re wrote the code like this : var txtbx = grdvw.rows[rowId].cells[0].children[0].id; and it got me to the column and cell I need but now I need to loop through the cell to get the specific control. the code posted is simplified version of actual code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.