开发者

Rendered code of Gridview in the Updatepanel Become Invisible

I have a gridview control inside an updatepanel. When I r开发者_运维问答un 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?


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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜