Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2010, 10:35 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Need Help Using Linkbutton in gridview

I am using linkbutton in my gridview to avoid the use of querystrings. The gridview is filled from a dataset.
I almost have it working but the text the linkbutton is displaying does not vary as a function of what row it is in. I need a way to associate the
text of the linkbutton with the row it is in. Any help is appreciated. Thank you.

Code:
<%@PageTitle=""Language="VB"MasterPageFile="~/secureds_deals.master" %>
<%@RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<scriptrunat="server">
Protected DealId AsInteger = 0
Protected DealName AsString
Protected StartDate AsDate
Protected ContractDate AsDate
Protected ClosingDate AsDate
Protected SubmitRole AsString
Protected Status AsString
Protected OfferNumber AsInteger
Protected OfferType AsString
Protected OfferAmount AsString
Protected OfferDateTime AsDate
Protected PctDown AsInteger
Protected SuggestedClosingDate AsDate
Protected CompletePct AsInteger
Protected Guarantor AsString
Protected Contingencies AsString
Protected Notes AsString
Protected BuyersAgent AsString
Protected MostRecent AsBoolean
Protected OfferId AsInteger = 0
Protected Purchaser1 AsString
Protected DealShortName AsString
Protected StreetAddress1, StreetAddress2, City, State, Country, PostalCode AsString
Protected Purchaser1PersonKey, Purchaser2PersonKey, BuyersAgentPersonKey AsInteger
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs)
'Session("DealID") was passed in
If Session("DealID") <= 0 Or Session("DealName") = ""Then Server.Transfer("Deals.aspx")
 
IfNot IsPostBack Then PopulateOfferGrid()
lblDealID.Text = "Deal ID: " & Session("DealID")
lblDealName.Text = "Deal Name: " & Session("DealName")
 
 
'Must get seller from different stored procedure
'Seller1 = DirectCast(dataSet.Tables(2).Rows(0).ItemArray(0), String)
EndSub
ProtectedSub PopulateOfferGrid()
Dim Conn AsNew SqlConnection(dsNegotiationGrid.ConnectionString)
Dim dataSet AsNew DataSet()
Dim adapter As SqlDataAdapter
Dim CmdGetNegotiationData AsNew SqlCommand("procGetNegotiationsByIDSelect", Conn)
Dim dealidparam AsNew SqlParameter("@dealid", SqlDbType.Int)
CmdGetNegotiationData.CommandType = Data.CommandType.StoredProcedure
dealidparam.Value = CInt(Session("DealID"))
CmdGetNegotiationData.Parameters.Add(dealidparam)
dealidparam.Direction = Data.ParameterDirection.Input
Conn.Open()
adapter = New SqlDataAdapter(CmdGetNegotiationData)
Try
adapter.Fill(dataSet)
 
DealID = CInt(dataSet.Tables(0).Rows(0).ItemArray(0))
DealName = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(1), String)
StartDate = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(2), Date)
ContractDate = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(3), Date)
ClosingDate = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(4), Date)
DealShortName = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(5), String)
SubmitRole = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(6), String)
Status = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(7), String)
OfferNumber = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(8), Int16)
OfferType = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(9), String)
OfferDateTime = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(10), Date)
PctDown = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(11), Int16)
OfferAmount = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(12), Int32)
SuggestedClosingDate = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(13), String)
CompletePct = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(14), Int16)
Guarantor = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(15), String)
Contingencies = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(16), String)
Notes = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(17), String)
MostRecent = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(18), Boolean)
OfferId = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(19), Int32)
StreetAddress1 = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(20), String)
StreetAddress2 = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(21), String)
City = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(22), String)
State = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(23), String)
Country = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(24), String)
PostalCode = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(25), String)
Purchaser1 = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(26), String)
BuyersAgent = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(27), String)
Purchaser1PersonKey = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(28), Int32)
Purchaser2PersonKey = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(29), Int32)
BuyersAgentPersonKey = DirectCast(dataSet.Tables(0).Rows(0).ItemArray(30), Int32)
gvNegotiationGrid.DataSource = dataSet
gvNegotiationGrid.DataBind()
Catch
Conn.Close()
lblMessage.Text = "There have not been any offers yet."
EndTry
EndSub
Sub gvNegotiationGrid_RowCommand(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
 
 
Dim rowindex AsInteger
rowindex = Convert.ToInt32(e.CommandArgument).ToString()
'Need Offer ID to pass to next page (DealSummary.aspx in session variable
'but don't want it to be in grid
'---------------------------------------------------------------------
'This would have worked if offerid was ij the grid
'Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
'Session("offerid") = CType(CType(row.Cells(1), DataControlFieldCell).Text, Integer)
'Note: Cell(1) is column 2
'-----------------------------------------------------------------------
Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
Session("offernumber") = CType(CType(row.Cells(1), DataControlFieldCell).Text, Integer)
'Note: Cell(1) is column 2 

Session("offerrownumber") = rowindex
If e.CommandName.Equals("Detail") Then
Response.Redirect("dealsummary.aspx")
EndIf
If e.CommandName="Respond"Then
Response.Redirect("respond.aspx")
EndIf
If e.CommandName = "Purchaser1"Then
Session("personid") = e.CommandArgument
Response.Redirect("peopledetail.aspx")
EndIf
If e.CommandName = "BuyersAgent"Then
Session("personid") = e.CommandArgument
Response.Redirect("peopledetail.aspx")
EndIf
EndSub
ProtectedSub gvNegotiationGrid_RowDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
 
 
 
If e.Row.RowType = DataControlRowType.DataRow Then
Dim btnDetail As Button = DirectCast(e.Row.FindControl("btnDetail"), Button)
Dim btnRespond As Button = DirectCast(e.Row.FindControl("btnRespond"), Button)
Dim ShowLink AsBoolean = _
CType(DataBinder.Eval(e.Row.DataItem, "mostrecent"), Boolean) ' add to db
If ShowLink=FalseThen
btnDetail.Visible = "False"
btnRespond.Visible="False"
EndIf
EndIf
EndSubProtectedSub btnAddOffer_Click(ByVal sender AsObject, ByVal e As System.EventArgs)
 
Session("offerrownumber") = 0
Server.Transfer("dealsummary.aspx")
EndSub
</script>
<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
<asp:LabelID="lblDealID"runat="server"CssClass="label"Text=""></asp:Label><br/>
<asp:LabelID="lblDealName"runat="server"CssClass="label"Text=""></asp:Label>
<divstyle="margin-top:25px;margin-bottom:10px;">
<asp:ButtonID="btnAddOffer"runat="server"Text="Add Offer"onclick="btnAddOffer_Click"/><br/><br/>
<asp:LabelID="lblMessage"runat="server"Cssclass="label"Text=""></asp:Label>
</div>
<div>
<asp:GridViewID="gvNegotiationGrid"runat="server"HorizontalAlign="Center"CellPadding="4"GridLines="None"
Font-Names="Verdana,Arial"Font-Size="0.7em"AutoGenerateColumns="False"AutoGenerateSelectButton="false"
OnRowCommand="gvNegotiationGrid_RowCommand"
OnRowDataBound="gvNegotiationGrid_RowDataBound"EmptyDataText="NoData"ForeColor="#333333"><Columns>
<asp:BoundFieldDataField="offertype"
HeaderText="Type"/><asp:BoundFieldDataField="offernumber"
HeaderText="#"/>
<asp:TemplateFieldHeaderText="Purchaser1">
<ItemTemplate>
<asp:LinkbuttonID="btnPurchaser1"CommandName="Purchaser1"
CommandArgument="<%# Purchaser1PersonKey %>"runat="server"Text="<%# Purchaser1 %>"/>
</ItemTemplate>
</asp:TemplateField><asp:BoundFieldDataField="status"
HeaderText="Status"/><asp:BoundFieldHtmlEncode="false"DataFormatString="{0: $##,#}"DataField="offeramount"
HeaderText="Offer Amount"/><asp:BoundFieldDataField="pctdown"
HeaderText="% Down"/><asp:BoundFieldDataField="SuggestedClosingDate"
HeaderText="Suggested Close"/><asp:BoundFieldDataField="Guarantor"
HeaderText="Guarantor"/>
<asp:BoundFieldDataField="Notes"
HeaderText="Notes"/>
<asp:BoundFieldHtmlEncode="false"DataFormatString="{0:g}"DataField="offerdatetime"
HeaderText="Made On"/><asp:BoundFieldDataField="SubmitRole"
HeaderText="Role"/><asp:TemplateFieldHeaderText="Purchaser1">
<ItemTemplate>
<asp:LinkbuttonID="btnBuyersAgent"CommandName="BuyersAgent"
CommandArgument="<%# BuyersAgentPersonKey %>"runat="server"Text="<%# BuyersAgent %>"/>
</ItemTemplate>
</asp:TemplateField><asp:BoundFieldDataField="CompletePct"
HeaderText="Complete %"/><asp:BoundFieldDataField="mostrecent"
HeaderText=""Visible="false"/>
<asp:TemplateFieldHeaderText="Detail">
<ItemTemplate>
<asp:ButtonID="btnDetail"CommandName="Detail"
CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>"runat="server"Text="Deal Summary"CssClass="gridbutton"
/>
</ItemTemplate>
</asp:TemplateField><asp:TemplateFieldHeaderText="Action">
<ItemTemplate>
<asp:ButtonID="btnRespond"CommandName="Respond"
CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>"runat="server"Text="Respond"
CssClass="gridbutton"/>
</ItemTemplate>
</asp:TemplateField></Columns>
<RowStyleBackColor="#F7F6F3"ForeColor="#333333"BorderColor="#336699"BorderWidth="1"BorderStyle="Solid"/>
<FooterStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="#284775"ForeColor="White"HorizontalAlign="Center"/>
<SelectedRowStyleBackColor="#E2DED6"Font-Bold="True"ForeColor="#333333"/>
<RowStyleHorizontalAlign="Center"/>
<HeaderStyleBorderColor="#336699"BorderStyle="Solid"BorderWidth="1px"Font-Names="Verdana"Font-Size="0.9em"HorizontalAlign="Center"VerticalAlign="Top"BackColor="#5D7B9D"Font-Bold="False"ForeColor="White"/>
<EditRowStyleBackColor="#999999"/>
<AlternatingRowStyleBorderColor="#336699"BorderStyle="Solid"BorderWidth="1px"HorizontalAlign="Center"BackColor="White"ForeColor="#284775"/>
</asp:GridView>
<asp:SqlDataSourceID="dsNegotiationGrid"runat="server"
ConnectionString="<%$ ConnectionStrings:DB_6056_securedeConnectionString %>">
</asp:SqlDataSource>
</div>
</asp:Content>
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with LinkButton lm111 ASP.NET 3.5 Professionals 0 August 28th, 2009 09:54 AM
Add LinkButton To Nested GridView Dynamcially rsearing ASP.NET 2.0 Professional 1 January 3rd, 2008 10:19 AM
how to hide linkbutton in edit mode of a gridview hertendreef ASP.NET 2.0 Basics 0 July 31st, 2007 03:08 PM
linkbutton control jake ASP.NET 1.0 and 1.1 Basics 1 December 6th, 2005 02:30 PM
linkbutton Beulah VS.NET 2002/2003 3 October 10th, 2005 05:00 PM



All times are GMT -4. The time now is 04:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.