Question about GridView

I add a GridView to a web page, then edit columns ...
select a field and then convert field to TemplateField
after that, I customize the field. In the EditItemTemplate I got a TextBox1 by default.
I add some code to GridView1_RowCreated method
TextBox textBox = (TextBox)e.Row.FindControl("TextBox1");
string clientID = textBox.ClientID;

here clientID is "TextBox1"
but it is not the id from the IE's view source ...

I try to add some javascript to control the textbox's content, but can't get the correct clientid.

Anyone can help
Thanks


Answer this question

Question about GridView

  • MagicDust

    That's the question I answered! The clientID you get in the server code ('TextBox1') is actually the base ID for the ID that will be created for the HTML object. And since each grid view row contains a textbox and the ID must be unique, gridview renders each object using the 'TextBox1' as base name and a counter.

  • MonicaR

    Dear papadi,

    I know what you mean.
    the following code
    TextBox textBox = (TextBox)e.Row.FindControl("TextBox1");
    string clientID = textBox.ClientID;

    the clientID should be "base ID" + counter.

    But it didn't.
    It just return "TextBox1" that is not correct.

  • MikeC06

    the reason is that one textbox is created for each row. Ofcourse all of these textboxes can not have the same clientID, so the gridView control creates a unique id for each row.


  • Khawar

    Thanks for your reply.
    But the question is that .... I didn't get the correct client id ...
    as I mentioned, the ClientID property is not the same with the browser's view source's textbox id.


  • Question about GridView