473,385 Members | 1,673 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,385 software developers and data experts.

Gridview: embedding a texbox and button in each row, passing info from that row to a function?

I'm making an administrative interface that lists records in a GridView.

For *each* row in the gridview, I would there to be two interface elements
in addition to some information associated with the record. Those interface
elements are a Button and a TextBox. The idea is that the administrator
using the interface will fill in an e-mail address and press the button if
they want to send that particular record to someone by e-mail. (I know how
to manage all of the e-mailing stuff.)

I know how to do a variation of this using a commandname on a simple link in
a repeater, but I have never done this with a textbox.

I've made many interfaces similar to what's described above using Classic
ASP.

How would I do this in a GridView? I imagine I'd build it using an
ItemTemplate. But I'm fuzzy on how to make the UI elements repeatable, how
to determine which row has been invoked, and how to grab the necessary
information out of the dynamically rendered/named UI elements or otherwise
pass the necessary info to the function I build to invoke the e-mailing
functionality.

Thanks,
-KF

Jul 8 '08 #1
4 2993
This question has been answered excellently, and with an example here:
http://www.experts-exchange.com/Prog...5.html?cid=239

I'll mirror any further information you supply or EE supplies in both
places.

Thanks!

"Ken Fine" <ke*****@newsgroup.nospamwrote in message
news:5E**********************************@microsof t.com...
I'm making an administrative interface that lists records in a GridView.

For *each* row in the gridview, I would there to be two interface elements
in addition to some information associated with the record. Those
interface elements are a Button and a TextBox. The idea is that the
administrator using the interface will fill in an e-mail address and press
the button if they want to send that particular record to someone by
e-mail. (I know how to manage all of the e-mailing stuff.)

I know how to do a variation of this using a commandname on a simple link
in a repeater, but I have never done this with a textbox.

I've made many interfaces similar to what's described above using Classic
ASP.

How would I do this in a GridView? I imagine I'd build it using an
ItemTemplate. But I'm fuzzy on how to make the UI elements repeatable, how
to determine which row has been invoked, and how to grab the necessary
information out of the dynamically rendered/named UI elements or otherwise
pass the necessary info to the function I build to invoke the e-mailing
functionality.

Thanks,
-KF
Jul 8 '08 #2
Hi KF,

thanks for posting and sharing us the information.

I haven't an account on thet www.experts-exchange.com/ so that I cannot see
that implementation. Here are some of my thoughts on this for your
information:

1. Use a TemplateField as an additional column in the GridView and put
Email TextBox and Button in that Templatefield's ItemTemplate. e.g.

===============
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnSendEmail" runat="server"
Text="SendTo: "
CommandName="Send" CommandArgument='<%#
((GridViewRow)Container).RowIndex %>' />
<asp:TextBox ID="txtEmail"
runat="server"></asp:TextBox>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
===============

2. We need to set CommandName and CommandArgument properties for the Button
in template. So that we can reference it in the Gridview's RowCommand event
later. Register the "RowCommand" event of GridView.

3. Here we add the code in "Rowcommand" event. We first ensure that the
CommandName is "Send", and then, get RowIndex from CommandArgument.
And Find controls from the GridViewRow and do the email sending stuff ...
=====================
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if(e.CommandName=="Send")
{
int rowindex = int.Parse(e.CommandArgument.ToString());

GridViewRow row = GridView1.Rows[rowindex];

Response.Write("<br/>Row: " + rowindex);

TextBox txt = row.FindControl("txtEmail") as TextBox;

Response.Write("<br/>Will send email to " + txt.Text);
}
}
============================

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Ken Fine" <ke*****@newsgroup.nospam>
References: <5E**********************************@microsoft.co m>
Subject: solution Re: Gridview: embedding a texbox and button in each row,
passing info from that row to a function?
>Date: Tue, 8 Jul 2008 13:26:22 -0700
>
This question has been answered excellently, and with an example here:
http://www.experts-exchange.com/Prog...P.NET/Q_235480
35.html?cid=239
>
I'll mirror any further information you supply or EE supplies in both
places.

Thanks!

"Ken Fine" <ke*****@newsgroup.nospamwrote in message
news:5E**********************************@microso ft.com...
>I'm making an administrative interface that lists records in a GridView.

For *each* row in the gridview, I would there to be two interface
elements
>in addition to some information associated with the record. Those
interface elements are a Button and a TextBox. The idea is that the
administrator using the interface will fill in an e-mail address and
press
>the button if they want to send that particular record to someone by
e-mail. (I know how to manage all of the e-mailing stuff.)

I know how to do a variation of this using a commandname on a simple
link
>in a repeater, but I have never done this with a textbox.

I've made many interfaces similar to what's described above using
Classic
>ASP.

How would I do this in a GridView? I imagine I'd build it using an
ItemTemplate. But I'm fuzzy on how to make the UI elements repeatable,
how
>to determine which row has been invoked, and how to grab the necessary
information out of the dynamically rendered/named UI elements or
otherwise
>pass the necessary info to the function I build to invoke the e-mailing
functionality.

Thanks,
-KF
Jul 9 '08 #3

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:6E**************@TK2MSFTNGHUB02.phx.gbl...
Hi KF,

thanks for posting and sharing us the information.

I haven't an account on thet www.experts-exchange.com/ so that I cannot
see
that implementation. Here are some of my thoughts on this for your
information:
Scroll to the bottom.
Jul 9 '08 #4
Hi KF,

How are you doing? Does the suggestion in my last reply help?
If there is any further question on this, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Wed, 09 Jul 2008 02:55:30 GMT
Subject: RE: solution Re: Gridview: embedding a texbox and button in each
row, passing info from that row to a function?
>
Hi KF,

thanks for posting and sharing us the information.

I haven't an account on thet www.experts-exchange.com/ so that I cannot
see
>that implementation. Here are some of my thoughts on this for your
information:

1. Use a TemplateField as an additional column in the GridView and put
Email TextBox and Button in that Templatefield's ItemTemplate. e.g.

===============
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnSendEmail" runat="server"
Text="SendTo: "
CommandName="Send" CommandArgument='<%#
((GridViewRow)Container).RowIndex %>' />
<asp:TextBox ID="txtEmail"
runat="server"></asp:TextBox>

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
===============

2. We need to set CommandName and CommandArgument properties for the
Button
>in template. So that we can reference it in the Gridview's RowCommand
event
>later. Register the "RowCommand" event of GridView.

3. Here we add the code in "Rowcommand" event. We first ensure that the
CommandName is "Send", and then, get RowIndex from CommandArgument.
And Find controls from the GridViewRow and do the email sending stuff ...
=====================
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if(e.CommandName=="Send")
{
int rowindex = int.Parse(e.CommandArgument.ToString());

GridViewRow row = GridView1.Rows[rowindex];

Response.Write("<br/>Row: " + rowindex);

TextBox txt = row.FindControl("txtEmail") as TextBox;

Response.Write("<br/>Will send email to " + txt.Text);
}
}
============================

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Jul 14 '08 #5

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
2
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it...
0
by: Yog | last post by:
Hi, How to access the value of a Texbox column(Template field) in gridview and to update a column next to it in the Gridview...! Example:Let's say there are four columns Product,Cost,Quantity...
2
by: | last post by:
I want to know how to make a clickable button or Command field on a GridView, and have the user's action a) fire a function and b) pass a data value from one of the GridView's columns to that...
2
by: dba123 | last post by:
I need help in coding the following or if you can just point me in the right direction: 1) Reading the follwoing XML document 2) Hook up a GridView to the data received from the XML document. ...
0
by: Larry Bud | last post by:
After spending two days looking at the options in adding a row to a gridview, I came up with my own that I'd like to share. I only can share pseudo-code right now, but maybe in the future I'll...
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
2
by: =?Utf-8?B?R2lyaXNo?= | last post by:
Hello All, I am displaying a report in a gridview and also in a separte html table. When the user clicks a print button, I print the report (from gridview or from html table). But I want to repeat...
0
KalariaNitya
by: KalariaNitya | last post by:
Hello, could anybody help me? i have gridview, inside gridview i have one Update button & textbox update button update the quantity entered in textbox. i want to update the quantity on textbox on...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.