views:

173

answers:

2

I have a gridview control inside an updatepanel. When I run the app and look at the source code generated, there is no source code about gridview. So, I can't aproach to the elements inside the gridview.

My question is, where is rendered code of gridview and how can I approach controls inside it?

+1  A: 

Are you trying to view your source code from your browser? This is never a good idea if you want to get access to your controls from within your gridview.

The way to go about accessing your controls from within your gridview is by finding them in your code behind. If you need to pass them to some client side scripts, you should use the ClientID attribute of your controls. Here's an example of something I do in my gridview's RowDataBound event.

protected void checkGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Button moveButton = (Button)e.Row.Cells[9].Controls[1];            
        moveButton.Attributes.Add("onclick","someJavaScript('"+moveButton.ClientID+"');");
    }
}

EDIT

To show you an example of what you'd have to do client side, here's a simple javascript function that uses the ClientID

function someJavaScript(buttonID)
{
  var button = document.getElementByID(buttonID);
  button.Click();
}

you could also use the $get function and say

var button = $get(buttonID);
Aaron
Thanks for response. I have already used the way you show me. This worked fine. But I have a button out of gridview and checkboxes inside the gridview. When I click the button, all checkboxes must be checked. Do you have a way for this issue?
mavera
A: 

For clarification: you have opened page in web browser, than press "View Source" and you had not able to locate HTML table corresponding to GridView, while it is exists on the screen? If so, then it is understandable - welcome to AJAX world of dynamic html. To see the table use:

  • OR FireFox+firebug plugin
  • OR IE + devtoolbar
  • OR Chrome

All these tools has menu: Inspect Element - pressing it you can see real DOM tree as expected.

Relative your question about "approaching". ASP.Net controls has very useful method property ClientID for all controls - this id contains non-human string how element named really including all parental name containers. Using this ID you can locate element for example by document.getElementByID

Dewfy