Where do you want to access it in the code-behind?
Typically you want to grab a control in an event of some sort, such as the
RowDataBound event...
The key is to find the control in a Row object and cast it to the
appropriate control type.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txt = (TextBox)e.Row.FindControl("DemoTextBox");
txt.Text = "Hello";
}
}
On 9/7/06, sx20200 <[EMAIL PROTECTED]> wrote:
>
> how can I access to web control in the GridView and use it's value
> in codebehind structure. I know It will be somethng like this
> "GridView_name.FindControl("x_FieldName")", but I do not know where
> to put it.I especially do not know how I should declare it.
> below code is my webform code.and I want to access the "text" value
> in gridview in code behind.
>
> <asp:GridView ID="GridView1" runat="server"
> AutoGenerateColumns="False" DataKeyNames="id"
> DataSourceID="SqlDataSource1">
> <Columns>
> <asp:BoundField DataField="text" HeaderText="text"
> SortExpression="text" />
> <asp:BoundField DataField="id" HeaderText="id"
> InsertVisible="False" ReadOnly="True"
> SortExpression="id" />
> </Columns>
> </asp:GridView>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$ ConnectionStrings:BConnStr %>"
> SelectCommand="SELECT [text], [id] FROM
> [art]"></asp:SqlDataSource>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNet2/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/AspNet2/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/