Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Tue, 8 Jul 2008 12:51:38 -0700,    group: microsoft.public.dotnet.framework.aspnet        back       


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
date: Tue, 8 Jul 2008 12:51:38 -0700   author:   Ken Fine am

solution Re: Gridview: embedding a texbox and button in each row, passing info from that row to a function?   
This question has been answered excellently, and with an example here:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23548035.html?cid=239

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

Thanks!

"Ken Fine" <kenfine@newsgroup.nospam> wrote in message 
news:5EE137F2-1188-4B34-8B21-52DEE3FB374A@microsoft.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
>
>
>
date: Tue, 8 Jul 2008 13:26:22 -0700   author:   Ken Fine am

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


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: 
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Ken Fine" <kenfine@newsgroup.nospam>
>References: 
>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/Programming/Languages/.NET/ASP.NET/Q_235480
35.html?cid=239
>
>I'll mirror any further information you supply or EE supplies in both 
>places.
>
>Thanks!
>
>"Ken Fine" <kenfine@newsgroup.nospam> wrote in message 
>news:5EE137F2-1188-4B34-8B21-52DEE3FB374A@microsoft.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
>>
>>
>> 
>
date: Wed, 09 Jul 2008 02:55:30 GMT   author:   (Steven Cheng [MSFT])

Re: solution Re: Gridview: embedding a texbox and button in each row, passing info from that row to a function?   
"Steven Cheng [MSFT]"  wrote in message 
news:6EFGL9W4IHA.1620@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.
date: Wed, 9 Jul 2008 23:24:44 +0100   author:   Marc

RE: solution Re: Gridview: embedding a texbox and button in each row, passing info from that row to a function?   
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: 
msdnmg@microsoft.com.

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

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------

>From: stcheng@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
>
>
date: Mon, 14 Jul 2008 07:51:09 GMT   author:   (Steven Cheng [MSFT])

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us