473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Retrieving the Cellcontent of a GridView


Hello!

I have bound a DataTable to my GridView. The DataTable has 3 Columns and
I display the Data with TemplateFields in my GridView. I have in the
first Column "LinkButton" - Field and in the other two Columns I have
"Label" - Fields!

How can I retrieve the Data of the third Column, when I click the
"LinkButton" from the same row?

I hope anyone could help me!

Here is the code from my GridView...

<asp:GridView ID="gdvData" runat="server" AutoGenerateColumns=False
CellPadding="6" ForeColor="#333333"
Style="left: 0px; position: relative; top: 25px" >

<Columns>

<asp:TemplateField HeaderText="Name" >
<ItemTemplate>
<asp:LinkButton ID="lkbName" runat="server"
Text='<%#Eval("Name")%>' OnClick="LinkButton_Click"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Erstellt am" >
<ItemTemplate>
<asp:Label ID="lblCreationTime" runat="server"
Text='<%#Eval("Erstellt am", "{0:d}")%>'/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="FullName" >
<ItemTemplate>
<asp:Label ID="lblFullName" runat="server"
Text='<%#Eval("Pfad")%>'/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

</Columns>

</asp:GridView>
Regards
Sebastian
Jul 26 '07 #1
1 1432
On Jul 26, 11:13 pm, Sebastian <doug4k...@web.dewrote:
Hello!

I have bound a DataTable to my GridView. The DataTable has 3 Columns and
I display the Data with TemplateFields in my GridView. I have in the
first Column "LinkButton" - Field and in the other two Columns I have
"Label" - Fields!

How can I retrieve the Data of the third Column, when I click the
"LinkButton" from the same row?

I hope anyone could help me!

Here is the code from my GridView...

<asp:GridView ID="gdvData" runat="server" AutoGenerateColumns=False
CellPadding="6" ForeColor="#333333"
Style="left: 0px; position: relative; top: 25px" >

<Columns>

<asp:TemplateField HeaderText="Name" >
<ItemTemplate>
<asp:LinkButton ID="lkbName" runat="server"
Text='<%#Eval("Name")%>' OnClick="LinkButton_Click"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Erstellt am" >
<ItemTemplate>
<asp:Label ID="lblCreationTime" runat="server"
Text='<%#Eval("Erstellt am", "{0:d}")%>'/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="FullName" >
<ItemTemplate>
<asp:Label ID="lblFullName" runat="server"
Text='<%#Eval("Pfad")%>'/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

</Columns>

</asp:GridView>

Regards
Sebastian
Hi Sebastian,
I have made a few changes to your provided code... and made worked
exactly what you want ...
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="lkbName" runat="server"
Text='<%#Eval("Name")%>' CommandName="Select" CommandArgument='<
%#Eval("Id")%>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
in the above code you can see that i have add commandname and
commandargument...
after that i subscripted the rowcommand event of the gridview...
and in rowcommand event handler... i did

protected void gdvData_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
GridViewRow row =
gdvData.Rows[Convert.ToInt32( e.CommandArgument)];
Label lbl = (Label) row.FindControl("lblFullName");
string name = lbl.Text;
}
}

worked very well for me...
please give a try...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com

Jul 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
0
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a...
1
by: s.bussing | last post by:
Hi, I have been struggling with the GridView the whole day, but can not get this solved. The rowupdating event in my Gridview doesn't give me the new values only the old ones. In my GridView I...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
7
by: Larry Bud | last post by:
I have a simple data object that returns two columns in a dataset, ID and DESC, for example. When I bind a dropdownlist to this <dataobjectmethod>, I have to manually enter the column names for...
0
by: gnewsgroup | last post by:
Usually, when I implement the PageIndexChanging and the Sorting event handler of a GridView, I have to load the data from the db right inside either of this event handler and then bind it to the...
7
by: splendid9 | last post by:
Problem in retrieving data from a XML file.......this is my code- protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ...
0
by: S_K | last post by:
Hi, I have an editible GridView that I can read the contents of each cell of the edit row as follows: int iEditIndex = GridView2.EditIndex; string strName = GridView2.Rows.Cells.Text; This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.