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

R

ratnakarp

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
 
A

alto

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!

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top