Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Gridview Coding issue  - EditItemTemplate

Posted on 2013-01-24
12
363 Views
Last Modified: 2013-01-27
I have a gridview which displays data regarding tasks assigned to various people, within the grid I have setup a template within the 'Resource' field, which reads a list of Resources from another table and then lets me choose a resource to update the table which is displaying the data in the gridview.
What I would like to do is, when a resource is selected from the drop down, I want an event to fire that will send an email to that resource, I have the code for sending the email and also the code for selecting the email address, my issue is how can I bind this to this type of control ? Or is there a better way to do this ?
0
Comment
Question by:ndr-itsolutions
12 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816671
Do you want to send an email as soon as the resource is selected in the dropdown or only when user Submit the update changes?
0
 

Author Comment

by:ndr-itsolutions
ID: 38816730
When the user submits the updated changes.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816738
You can do that in the RowCommand or RowUpdate Event handler.
It will be a single row update right or you have multiple row updates at a single time?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:ndr-itsolutions
ID: 38816758
Yes, a single row.

Any example code ?
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38816822
It would be something like this:

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
        string resource = e.NewValues[1].ToString(); //1 is the index for your resource column
        //the row was updated and you can send your email here.
}
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38817617
http://www.codeproject.com/Questions/163877/Row-updating-event-in-gridview-ASP-NET

http://stackoverflow.com/questions/987980/getting-a-selected-value-from-the-drop-down-list-inside-a-gridview-on-update

try to find the control under RowUpdated event


try something like this

protected void gv_UpdateRow(string arg)
{
    int currentIndex = gv.EditIndex;
    gv.EditIndex = -1;

    GridViewRow currentRow = gv.Rows[currentIndex];

    try
    {
      string value2 = ((DropDownList)currentRow.FindControl("ddlValueTwo")).SelectedItem.ToString();
//Place your email code here and test 
    }
    catch
    {
        Response.Write("error");
    }


    BindGridView(); 
}

Open in new window


GEt DDL selected value in gridview

http://www.dotnetfunda.com/codes/code3389-how-to-get-dropdownlist-selected-value-in-inside-gridview-in-aspnet.aspx
http://stackoverflow.com/questions/5000489/how-to-edit-and-update-row-values-in-grid-view
0
 

Author Comment

by:ndr-itsolutions
ID: 38817739
Sorry should have said, I'm using vb.net
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38817980
Here, use this

http://converter.telerik.com/
Protected Sub gv_UpdateRow(arg As String)
	Dim currentIndex As Integer = gv.EditIndex
	gv.EditIndex = -1

	Dim currentRow As GridViewRow = gv.Rows(currentIndex)

	Try
			'Place your email code here and test 
		Dim value2 As String = DirectCast(currentRow.FindControl("ddlValueTwo"), DropDownList).SelectedItem.ToString()
	Catch
		Response.Write("error")
	End Try


	BindGridView()
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================

Open in new window

0
 

Author Comment

by:ndr-itsolutions
ID: 38818247
So where would I insert this code ?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38820712
Can you tell what code you are trying to use? Did you follow the links posted?
The basic idea is handle your GridView's RowUpdated event.
0
 

Author Comment

by:ndr-itsolutions
ID: 38823745
I'm looking to use the first suggestion

 Dim resource As String = e.NewValues(1).ToString()
        '1 is the index for your resource column
        'the row was updated and you can send your email here.

I've placed it in the code behind of the web form that contains the gridview.
0
 

Author Closing Comment

by:ndr-itsolutions
ID: 38824997
This worked a treat after I worked out that I had not added my sub routine to the gridview.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 30
Convert Select to DropDownListFor MVC 5 2 29
SSIS On fail action 5 37
Where is this file? 3 25
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question