/    Sign up×
Community /Pin to ProfileBookmark

value from input box in gridview

I need to get the value of a textbox in a gridview. I have found this solution on the web and it looks very good but I am having trouble with it. Thanks to netomatix.com which is the source of this code.
When I click a row the event fires. The gridViewCtlId variable correctly id’s the correct grid (gvMDE in my case). But.. the next function to run, getGridViewControl, does not work. I believe it is assigned the object to a variable with this line
if (null == gridViewCtl)
{
gridViewCtl = document.getElementById(gridViewCtlId);
}
But the gridViewCtl always comes back null. Thus, nothing else works. I am passing an integer ID into the onGridViewRowSelected(rowIdx) line and I have verified that it is being passed.
Anyone have any tips on how to get this working? Here is the complete code.

<script language=”javascript” type=”text/javascript”>
var gridViewCtlId = ‘<%=gvMDE.ClientID%>’;
var gridViewCtl = null;
var curSelRow = null;
var curRowIdx = -1;
function getGridViewControl()
{
if (null == gridViewCtl)
{
gridViewCtl = document.getElementById(gridViewCtlId);
alert(“gridviewctl = ” + gridViewCtl)
}
}

function onGridViewRowSelected(rowIdx)
{
var selRow = getSelectedRow(rowIdx);
if (null != selRow)
{
curSelRow = selRow;
var cellValue = getCellValue(rowIdx, 0);
alert(cellValue);
}
}

function getSelectedRow(rowIdx)
{
return getGridRow(rowIdx);
}

function getGridRow(rowIdx)
{
getGridViewControl();
if (null != gridViewCtl)
{
return gridViewCtl.rows[rowIdx];
}
return null;
}

function getGridColumn(rowIdx, colIdx)
{
var gridRow = getGridRow(rowIdx);
if (null != gridRow)
{
return gridRow.cells[colIdx];
}
return null;
}

function getCellValue(rowIdx, colIdx)
{
var gridCell = getGridColumn(rowIdx, colIdx);
if (null != gridCell)
{
return gridCell.innerText;
}
return null;
}

</script>

end of java…..

here is the first few rows of the gridview

<table id=”gvMDE_ctl00″ cellspacing=”0″ cellpadding=”2″ border=”0″ id=”gvMDE” style=”color:Black;background-color:LightGoldenrodYellow;border-color:Tan;border-width:1px;border-style:solid;width:95%;border-collapse:collapse;”>
<tr id=”gvMDE_ctl01″ onclick=”onGridViewRowSelected(0)” style=”background-color:Tan;font-weight:bold;”>
<th id=”gvMDE_ctl01_ctl00″ scope=”col”>Key</th><th id=”gvMDE_ctl01_ctl03″ scope=”col”>Description</th><th id=”gvMDE_ctl01_ctl06″ scope=”col”>&nbsp;</th><th id=”gvMDE_ctl01_ctl07″ scope=”col”>&nbsp;</th><th id=”gvMDE_ctl01_ctl08″ scope=”col”>Sample date time</th><th id=”gvMDE_ctl01_ctl09″ scope=”col”>&nbsp;</th><th id=”gvMDE_ctl01_ctl10″ scope=”col”>&nbsp;</th><th id=”gvMDE_ctl01_ctl11″ scope=”col”>value</th><th id=”gvMDE_ctl01_ctl12″ scope=”col”>UnitName</th><th id=”gvMDE_ctl01_ctl13″ scope=”col”>&nbsp;</th>
</tr><tr id=”gvMDE_ctl02″ onclick=”onGridViewRowSelected(1)” style=”color?arkBlue;font-weight:bold;”>
<td id=”gvMDE_ctl02_ctl02″ style=”width:40px;”>
<span id=”gvMDE_ctl02_lblSessionKey”>38</span>
</td><td id=”gvMDE_ctl02_ctl11″ align=”left” style=”width:240px;”>
<span id=”gvMDE_ctl02_lblDescription”>SWC Influent Temp</span>
</td><td id=”gvMDE_ctl02_ctl20″>
<span id=”gvMDE_ctl02_SPACER2″ style=”display:inline-block;width:15px;”></span>
</td><td id=”gvMDE_ctl02_ctl00″>

</td><td id=”gvMDE_ctl02_ctl25″>
<span id=”gvMDE_ctl02_lblSampledateTime”>7/3/2008</span>
</td><td id=”gvMDE_ctl02_ctl28″>

</td><td id=”gvMDE_ctl02_ctl31″>
<span id=”gvMDE_ctl02_SPACER1″ style=”display:inline-block;width:15px;”></span>
</td><td id=”gvMDE_ctl02_ctl34″ align=”center”>
<input name=”gvMDE$ctl02$txtValue” type=”text” value=”finally” id=”gvMDE_ctl02_txtValue” />

<br />
</td><td id=”gvMDE_ctl02_ctl37″ style=”width:40px;”>
<span id=”gvMDE_ctl02_lblUnitName”>gvMDE$ctl02$ctl00</span>
</td><td id=”gvMDE_ctl02_ctl40″>

</td>
</tr><tr id=”gvMDE_ctl03″ onclick=”onGridViewRowSelected(2)” style=”color:DarkBlue;background-color:PaleGoldenrod;font-weight:bold;”>
<td id=”gvMDE_ctl03_ctl02″ style=”width:40px;”>
<span id=”gvMDE_ctl03_lblSessionKey”>38</span>
</td><td id=”gvMDE_ctl03_ctl11″ align=”left” style=”width:240px;”>
<span id=”gvMDE_ctl03_lblDescription”>SWC Influent pH</span>
</td><td id=”gvMDE_ctl03_ctl20″>
<span id=”gvMDE_ctl03_SPACER2″ style=”display:inline-block;width:15px;”></span>
</td><td id=”gvMDE_ctl03_ctl00″>

</td><td id=”gvMDE_ctl03_ctl25″>
<span id=”gvMDE_ctl03_lblSampledateTime”>7/3/2008</span>
</td><td id=”gvMDE_ctl03_ctl28″>

</td><td id=”gvMDE_ctl03_ctl31″>
<span id=”gvMDE_ctl03_SPACER1″ style=”display:inline-block;width:15px;”></span>
</td><td id=”gvMDE_ctl03_ctl34″ align=”center”>
<input name=”gvMDE$ctl03$txtValue” type=”text” value=”finally” id=”gvMDE_ctl03_txtValue” />

<br />
</td><td id=”gvMDE_ctl03_ctl37″ style=”width:40px;”>
<span id=”gvMDE_ctl03_lblUnitName”>gvMDE$ctl03$ctl00</span>
</td><td id=”gvMDE_ctl03_ctl40″>

</td>
</tr>

thank you….

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ecsmoore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...