Retreving the text value of LinkButton in template column of a datagrid

Discussion in 'ASP .Net Datagrid Control' started by ratnakarp@gmail.com, May 17, 2005.

  1. Guest

    Hi,


    I'm tring to use template column in a datagrid and added a link button
    in item template. I'm loading the value of link button dynamically by
    binding dataset to a datagrid. When i click linkbutton on the webform
    ,i should be able to retrieve the text value of the link button. how
    can i do that? Below i'm posting my code, can you please tell me where
    i'm going wrong?


    ASP.NET CODE
    --------------


    <asp:datagrid id=DataGrid1 runat="server" Width="256px" Height="225px"
    AutoGenerateColumns="False" OnItemCommand ="DataGrid1_Item1">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton ID = "link1"
    Runat=server><%#DataBinder.Eva­l(Container.DataItem,
    "city")%></asp:LinkButton>
    </It­emTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>


    C#.NET
    ---------


    public void DataGrid1_Item1(object sender, DataGridCommandEventArgs e)
    {
    string city =
    ((LinkButton)DataGrid1.SelectedItem.Cells[­0].Controls[0]).Text ;
    Response.Write("city is:" + city);
    }


    Can you please tell me how to retreive the text value of link button
    control in a datagrid ?


    Thanks & Regards,
    Ratnakar Pedagani
     
    , May 17, 2005
    #1
    1. Advertising

  2. alto Guest

    Ratnakar,

    you don't use SelectedItem on your grid. Everything you need is in the
    DataGridCommandEventArgs object, passsed as param. So you'll have smt like
    this:

    ( (<your cast here>)e.Item.Cells[<column index here>] ).<property you need>

    Good luck!

    <> wrote in message
    news:...
    Hi,


    I'm tring to use template column in a datagrid and added a link button
    in item template. I'm loading the value of link button dynamically by
    binding dataset to a datagrid. When i click linkbutton on the webform
    ,i should be able to retrieve the text value of the link button. how
    can i do that? Below i'm posting my code, can you please tell me where
    i'm going wrong?


    ASP.NET CODE
    --------------


    <asp:datagrid id=DataGrid1 runat="server" Width="256px" Height="225px"
    AutoGenerateColumns="False" OnItemCommand ="DataGrid1_Item1">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton ID = "link1"
    Runat=server><%#DataBinder.Eva­l(Container.DataItem,
    "city")%></asp:LinkButton>
    </It­emTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>


    C#.NET
    ---------


    public void DataGrid1_Item1(object sender, DataGridCommandEventArgs e)
    {
    string city =
    ((LinkButton)DataGrid1.SelectedItem.Cells[­0].Controls[0]).Text ;
    Response.Write("city is:" + city);
    }


    Can you please tell me how to retreive the text value of link button
    control in a datagrid ?


    Thanks & Regards,
    Ratnakar Pedagani
     
    alto, May 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW1pdCBQYW5keWE=?=

    retreving dynamically added controls using C#

    =?Utf-8?B?QW1pdCBQYW5keWE=?=, Feb 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    761
    =?Utf-8?B?QW1pdCBQYW5keWE=?=
    Feb 13, 2004
  2. pviewer

    Retreving a context menu's hWnd

    pviewer, Jan 16, 2011, in forum: C Programming
    Replies:
    2
    Views:
    557
    Kenny McCormack
    Jan 16, 2011
  3. Esperanza

    Template column base on another column value

    Esperanza, Feb 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    176
    Elton Wang
    Feb 21, 2005
  4. Replies:
    2
    Views:
    246
    jyoti
    Aug 19, 2006
  5. Hemant Shah
    Replies:
    7
    Views:
    121
    Hemant Shah
    Jan 9, 2004
Loading...

Share This Page