Retrieving the Cellcontent of a GridView

S

Sebastian

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
 
M

Masudur

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
 

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

Top