Get Datalist Row number (index) thru javascript

J

john

Condition:

A Timesheet entry page with 2 weeks displayed in a Datalist control.



What I need to do is associate a single Memo textbox back to the clicked,
Time entered Textbox with javascript.



I have 16 textboxes per row, with a bound hiddenfield for each of those for
the memo to be stored in for that day's column field, per project row. What
I do not know how to do is on the "onblur" event of the Memo textbox write
back to the hiddenfield what is written into the Memo.



Because there are many rows, and each row has a unique ClientID, I'm not
sure how to get the row number from javascript, as it not a selected row,
just a clicked Textbox on the Time entered textbox of a row.



I can pass it the original TextBox clicked day ID, but how do I get or pass
it the row number. I've tried using the ClientID Method as below but the
build fails.



I basically need to get the Datalist Row number or pass it thru to the
function from just a TextBox Click without a PostBack, just JavaScript.



The hiddenfields Id's are Hm1 thru Hm16



<script language="javascript" type="text/javascript">

Var txtday

function Memo_Out()

{

document.getElementById("<%= Hm2.ClientID %>").value =
document.getElementById("DataListTime_ctl04_txtMemo").value

}



// This is hardcode way of sending the stored Memo to the Memo textbox for
review or editing thru an onfocus event of the textbox, but the ctl01 part
needs to part variable also to represent the row number of the textbox I
clicked (ctl01, ctl02, ctl03, etc).



function Memo1_IN(dayID)

{

txtday = dayID // Always Live Variable for use in Memo_Out if Needed

document.getElementById("DataListTime_ctl04_txtMemo").value =
document.getElementById("DataListTime_ctl01_Hm2").value

}



</script>



Thanks

John
 
T

Toze

hi john try this

onitemdatabond of the datalist
Dim counter As Integer = 1
While counter < 17

Dim tbox As TextBox = e.Item.FindControl("TextBox" & counter)

Dim hidden As HiddenField = e.Item.FindControl("HiddenField" & counter)

tbox.Attributes.Add("onblur", "item_onBlur('" & tbox.ClientID & "', '" &
hidden.ClientID & "', " & e.Item.ItemIndex & ");")

counter += 1

End While







javascript:

function item_onBlur(tboxId, hiddenId, rowIndex)

{

var tbox = document.getElementById(tboxId);

var hidden = document.getElementById(hiddenId);



}

hope it helps
 
J

john

Thanks, that is what I needed
John
Toze said:
hi john try this

onitemdatabond of the datalist
Dim counter As Integer = 1
While counter < 17

Dim tbox As TextBox = e.Item.FindControl("TextBox" & counter)

Dim hidden As HiddenField = e.Item.FindControl("HiddenField" & counter)

tbox.Attributes.Add("onblur", "item_onBlur('" & tbox.ClientID & "', '" &
hidden.ClientID & "', " & e.Item.ItemIndex & ");")

counter += 1

End While







javascript:

function item_onBlur(tboxId, hiddenId, rowIndex)

{

var tbox = document.getElementById(tboxId);

var hidden = document.getElementById(hiddenId);



}

hope it helps
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top