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

D

Danielle

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:[email protected]?subject=Test
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>
 
C

Cowboy \(Gregory A. Beamer\)

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! |
********************************************
 
D

Danielle

Gregory -

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

Thanks :)
Danielle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top