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

Gridview - visual basic - need to know which row contains the clickedbutton.

All -

Thanks in advance for any help you can provide. I've been working with
a GridView in Visual Basic for a long time trying to get a list of
contacts and to be able to edit and delete the contacts as well as
send email on behalf of hte contact. I originally started with the
built in update/delete functions of the gridview but I could never get
them to work... then I created new pages that are launched on button
clicks as shown below. I'm using javascript so that the code can be
run client-side.

This actually was working, but I found that if I had more than one
contact the contactID would always be determined to be the last
contact in the list.

I had the code-behind (which I believe used the OnRowDataBound event),
but in trying to solve this issue a number of ways I think I must have
lost it.

Can anyone please, please tell me how I can know what row is clicked
when the user clicks one of the buttons below? This is fairly time
sensitive and is also outside the scope of my normal job so I'm in the
crunch of needing something fairly quickly on a number of levels. I'm
also fairly new to all this - it's an ugly combination.

Thanks
Danielle

<asp:GridView ID="gdContacts" runat="server"
AutoGenerateColumns="False"
AllowSorting="True"
BackColor="#FFEA97"
CellPadding="6"
DataKeyNames="ID,Guid,ContactEmail"
DataSourceID="sqlContactInfo"
EmptyDataText = "<None>"
Font-Names="Verdana"
Font-Size="Small">
<Columns>
<asp:TemplateField HeaderText="Contact Name"
SortExpression="ContactName">
<EditItemTemplate>
<asp:TextBox ID="txtContactName"
runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<
%# Bind("ContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Email"
SortExpression="ContactEmail">
<EditItemTemplate>
<asp:TextBox ID="txtContactEmail"
runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<
%# Bind("ContactEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Phone"
SortExpression="ContactPhone">
<EditItemTemplate>
<asp:TextBox ID="txtContactPhone"
runat="server" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<
%# Bind("ContactPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID"
InsertVisible="False" Visible="False" >
<EditItemTemplate>
<asp:TextBox ID="txtID" runat="server" Text='<
%# Bind("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#
Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Guid"
InsertVisible="False" Visible="False" >
<EditItemTemplate>
<asp:TextBox ID="txtGuid" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGuid" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button" onclick="window.open('./
Edit.aspx?ID=<%=CStr(contactID)%>');" value="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button" onclick="window.open('./
Delete.aspx?ID=<%=CStr(contactID)%>');" value="Delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button"
onclick="window.open('mailto:dd@xyz.com?subject=Te st
Message&body=Agreement Guid: <%=CStr(agreementID)%>');" value="Submit
Case" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE16D" />
</asp:GridView>
<asp:SqlDataSource ID="sqlContactInfo" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString_Stage %>"
SelectCommand="usp_Get_Stuff"
SelectCommandType="StoredProcedure" >
<SelectParameters>
<asp:QueryStringParameter Name="agreementGuid"
QueryStringField="agreementGuid" Type="String" />
</SelectParameters>

</asp:SqlDataSource>
Jun 27 '08 #1
2 1467
My suggestion is to use a FormView to do the actual updates. Then you can
set up the insert query without the autogenerated field and you should be
fine.

I should have an example from Expression Web that is pure drag and drop. If
I can find it rather quickly, I will post something, as the instructions are
actually rather simple.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"Danielle" <wx****@aol.comwrote in message
news:e7**********************************@w7g2000h sa.googlegroups.com...
All -

Thanks in advance for any help you can provide. I've been working with
a GridView in Visual Basic for a long time trying to get a list of
contacts and to be able to edit and delete the contacts as well as
send email on behalf of hte contact. I originally started with the
built in update/delete functions of the gridview but I could never get
them to work... then I created new pages that are launched on button
clicks as shown below. I'm using javascript so that the code can be
run client-side.

This actually was working, but I found that if I had more than one
contact the contactID would always be determined to be the last
contact in the list.

I had the code-behind (which I believe used the OnRowDataBound event),
but in trying to solve this issue a number of ways I think I must have
lost it.

Can anyone please, please tell me how I can know what row is clicked
when the user clicks one of the buttons below? This is fairly time
sensitive and is also outside the scope of my normal job so I'm in the
crunch of needing something fairly quickly on a number of levels. I'm
also fairly new to all this - it's an ugly combination.

Thanks
Danielle

<asp:GridView ID="gdContacts" runat="server"
AutoGenerateColumns="False"
AllowSorting="True"
BackColor="#FFEA97"
CellPadding="6"
DataKeyNames="ID,Guid,ContactEmail"
DataSourceID="sqlContactInfo"
EmptyDataText = "<None>"
Font-Names="Verdana"
Font-Size="Small">
<Columns>
<asp:TemplateField HeaderText="Contact Name"
SortExpression="ContactName">
<EditItemTemplate>
<asp:TextBox ID="txtContactName"
runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<
%# Bind("ContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Email"
SortExpression="ContactEmail">
<EditItemTemplate>
<asp:TextBox ID="txtContactEmail"
runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<
%# Bind("ContactEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Phone"
SortExpression="ContactPhone">
<EditItemTemplate>
<asp:TextBox ID="txtContactPhone"
runat="server" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<
%# Bind("ContactPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID"
InsertVisible="False" Visible="False" >
<EditItemTemplate>
<asp:TextBox ID="txtID" runat="server" Text='<
%# Bind("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#
Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Guid"
InsertVisible="False" Visible="False" >
<EditItemTemplate>
<asp:TextBox ID="txtGuid" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGuid" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button" onclick="window.open('./
Edit.aspx?ID=<%=CStr(contactID)%>');" value="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button" onclick="window.open('./
Delete.aspx?ID=<%=CStr(contactID)%>');" value="Delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<input type="button"
onclick="window.open('mailto:dd@xyz.com?subject=Te st
Message&body=Agreement Guid: <%=CStr(agreementID)%>');" value="Submit
Case" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE16D" />
</asp:GridView>
<asp:SqlDataSource ID="sqlContactInfo" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString_Stage %>"
SelectCommand="usp_Get_Stuff"
SelectCommandType="StoredProcedure" >
<SelectParameters>
<asp:QueryStringParameter Name="agreementGuid"
QueryStringField="agreementGuid" Type="String" />
</SelectParameters>

</asp:SqlDataSource>
Jun 27 '08 #2
Gregory -

If you can find something I'd be really appreciative.

Thanks :-)
Danielle
Jun 27 '08 #3

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....
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
5
by: brian | last post by:
I have a gridview that will contain 5000 + rows that is initially loaded into a dataset and bound to a gridview. On the form I have textboxes and dropdown list's I use to let the user fill in and...
4
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
6
by: ahling | last post by:
Hi, I have a question to ask regarding the gridview control in visual basic 2008. How to bound data to the gridview control? I tried to link the gridview to the sqlsourcedata but after...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
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...
0
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,...
0
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...

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.