473,804 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3018
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*****@newsgr oup.nospamwrote in message
news:5E******** *************** ***********@mic rosoft.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:TemplateFi eld>
<ItemTemplate >
<asp:Button ID="btnSendEmai l" runat="server"
Text="SendTo: "
CommandName="Se nd" CommandArgument ='<%#
((GridViewRow)C ontainer).RowIn dex %>' />
<asp:TextBox ID="txtEmail"
runat="server"> </asp:TextBox>

</ItemTemplate>
</asp:TemplateFie ld>
</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_RowCo mmand(object sender,
GridViewCommand EventArgs e)
{
if(e.CommandNam e=="Send")
{
int rowindex = int.Parse(e.Com mandArgument.To String());

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****@microsof t.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*****@newsgr oup.nospam>
References: <5E************ *************** *******@microso ft.com>
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*****@newsgr oup.nospamwrote in message
news:5E******* *************** ************@mi crosoft.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
administrato r 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
functionalit y.

Thanks,
-KF
Jul 9 '08 #3

"Steven Cheng [MSFT]" <st*****@online .microsoft.comw rote in message
news:6E******** ******@TK2MSFTN GHUB02.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****@microsof t.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:TemplateFi eld>
<ItemTemplate >
<asp:Button ID="btnSendEmai l" runat="server"
Text="SendTo : "
CommandName="Se nd" CommandArgument ='<%#
((GridViewRow) Container).RowI ndex %>' />
<asp:TextBox ID="txtEmail"
runat="server" ></asp:TextBox>

</ItemTemplate>
</asp:TemplateFie ld>
</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_RowCo mmand(object sender,
GridViewComman dEventArgs e)
{
if(e.CommandNam e=="Send")
{
int rowindex = int.Parse(e.Com mandArgument.To String());

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
13758
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. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
2
4463
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 correct, that PageSize equals the max size of the result set? 2. Is there a way to make asp cache the search result, so the domain controller won't be to bother by all the lookups, and also to speed up
0
1499
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 Required(Textbox type template field in Gridview) and Total...! Totla shud get updated by Cost*QuantityRequired as soon as the user focuses on next row in the gridview.....!
2
2447
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 function. Long version: ASP.NET's usual paradigm with master-detail editing is to have you define a commandfield, and on your detail view to define a second datasource that uses the SelectedValue of the GridView to determine what the detail record...
2
13308
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. The Grid should read lke this: Title Description Title
0
6503
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 write a full fledged article. I didn't like the options, such as putting your controls (really, DUPLICATING your controls) in the Footer for a variety of reasons. First, I don't like the idea of having to do things twice, including any...
4
6087
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 are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My object method to perform the update:
2
11076
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 the gridview's header and the html table header row in all printed pages. The print for grid and html table is done separately. Can someone tell me how to make the header print in all pages? Thanks
0
2538
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 ENTER event. i had done below code: page_load()
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.