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

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

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

    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.DataIte m,
    "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

    ratnakarp@gmail.com Guest

  2. Similar Questions and Discussions

    1. How to set different label value in datagrid template column?
      Hi all, I have a datagrid with a stock label "lblStock". Here's is what i what to do : 1. If the quantity value retrieved from database is = 0...
    2. HeaderTemplate in Template Column in a datagrid
      Hi, I have a checkbox in the header of a template column in a datagrid. How can I check during runtime that whether checkbox is checked or not? ...
    3. Dinamically changing the Text Field of a LinkButton in a DataGrid
      Hello, I've run into a problem and I'm not sure if this is a limitation of dotNet or I'm doing something bad, I've a TemplateColumn in a...
    4. Bound Column or Template Column (w dAdapater?) in DataGrid
      I am able to get the data using DataAdapter and the DataReader. I am more inclined to use DataAdapter because I want to update the data on the SQL...
    5. DataGrid / Template Column
      I have a DataGrid with a template column (displaying a checkbox). The rows of the datagrid are being populated from a db table. Currently, only one...
  3. #2

    Default Re: Retreving the text value of LinkButton in template column of a datagrid

    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!

    <ratnakarp@gmail.com> wrote in message
    news:1116341089.431257.111120@f14g2000cwb.googlegr oups.com...
    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.DataIte m,
    "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 Guest

  4. #3

    Default Re: Retreving the text value of LinkButton in template column of a datagrid

    please try this.

    public void datagrid1_Item1(Object sender,DataGridItemEventArgs e)
    {
    string City=((LinkButton)(e.Item.FindControl("LnkButtonNa me"))).Text;//LNKButtonName indicates name of your link button
    }
    star Guest

  5. #4

    Default Re: Retreving the text value of LinkButton in template column of a datagrid

    please try this
    public void datagrid1_Item1(Object sender,DataGridItemEventArgs e)
    {
    string City=((LinkButton)(e.Item.FindControl("LnkButtonNa me"))).Text;//LNKButtonName indicates name of your link button
    }
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139