Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Retrieving the Cellcontent of a GridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sebastian - 26 Jul 2007 18:13 GMT
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
Masudur - 28 Jul 2007 11:58 GMT
> Hello!
>
[quoted text clipped - 46 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.