Hi
I have a db with 2 tables that I want to bind to a grid depending on a
selection in a Dropdownlist
Also I want to be able to select a row from the gris to fill some
textboxes.
The databases are static in that they will not be updated they are just
for viewing
I have everything working but not to perfection
A few issues I am trying to solve
1) If I select a row from the select button - can I avoid a postback and
just fill the textboxes with the
data in the grid row
2)It seems that I have to have the Grid.Bind() in the Page_Load - I
thought I would only need to load the
Datasets once and just re-bind to Grid????
3)The one problem I do have is that if I hit a CommandButton that
actually needs to go to the server
I lose the grid
Thanks
Steve
Dim MyConnection As SqlConnection
Dim DS As DataSet
Dim DS2 As DataSet
Public Class DLLClass
<DllImport("Pay ment.dll")> _
Public Shared Function _
CalcPaymentCH(B yVal lLOS As Integer, ByVal dCW As Double, ByVal
lLTP As Integer, ByVal lHTP As Integer, ByVal dALOS As Double, ByVal
dCHF As Double, ByVal dFACTOR As Double) As Double
End Function
End Class
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
MyConnection = New SqlConnection(" Data Source=localhos t;Initial
Catalog=Stats;U ser Id=sa;Password= ;")
If Not (IsPostBack) Then ' Evals true first time browser hits
the page
'Put user code to initialize the page here
'BindGrid() 'Should be here ????
ddlFormula.Item s.Add("")
ddlFormula.Item s.Add("Swiss 2003")
ddlFormula.Item s.Add("Swiss 2004")
txtCHF.Text = "5000"
txtFactor.Text = "0.7"
txtHTPF.Text = "2.43"
txtLTPF.Text = "2.0"
txtLTPF.Visible = False
txtHTPF.Visible = False
lblLTPF.Visible = False
lblHTPF.Visible = False
End If
BindGrid()
End Sub
Private Sub ddlFormula_Sele ctedIndexChange d(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ddlFormula.Sele ctedIndexChange d
If (ddlFormula.Sel ectedValue = "Swiss 2004") Then
txtLTPF.Visible = True
txtHTPF.Visible = True
lblLTPF.Visible = True
lblHTPF.Visible = True
Datagrid1.DataS ource = DS2.Tables("CHA P2004").Default View
Datagrid1.DataB ind()
Else
txtLTPF.Visible = False
txtHTPF.Visible = False
lblLTPF.Visible = False
lblHTPF.Visible = False
Datagrid1.DataS ource = DS.Tables("CHAP 2003").DefaultV iew
Datagrid1.DataB ind()
End If
End Sub
Private Sub BindGrid()
Dim MyCommand As SqlDataAdapter
MyCommand = New SqlDataAdapter( "SELECT * FROM CHAP2003",
MyConnection)
DS = New DataSet
MyCommand.Fill( DS, "CHAP2003")
MyCommand = New SqlDataAdapter( "SELECT * FROM CHAP2004",
MyConnection)
DS2 = New DataSet
MyCommand.Fill( DS2, "CHAP2004")
'Datagrid1.Data Source = DS.Tables("CHAP 2003").DefaultV iew
'Datagrid1.Data Bind()
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles btnCalculate.Cl ick
Dim dPayment As Double
If (ddlFormula.Sel ectedValue = "Swiss 2003") Then
dPayment = DLLClass.CalcPa ymentCH(20, 1.5, 5, 15, 10.5,
5000.0, 0.7)
ElseIf (ddlFormula.Sel ectedValue = "Swiss 2004") Then
End If
txtPayment.Text = Str(dPayment)
End Sub
Private Sub Datagrid1_Selec tedIndexChanged (ByVal sender As Object,
ByVal e As System.EventArg s) Handles Datagrid1.Selec tedIndexChanged
txtDRG.Text = Datagrid1.Selec tedItem.Cells(1 ).Text.ToString ()
txtWT.Text = Datagrid1.Selec tedItem.Cells(2 ).Text.ToString ()
txtALOS.Text = Datagrid1.Selec tedItem.Cells(3 ).Text.ToString ()
txtHTP1.Text = Datagrid1.Selec tedItem.Cells(4 ).Text.ToString ()
txtLTP.Text = Datagrid1.Selec tedItem.Cells(5 ).Text.ToString ()
End Sub
End Class
<div style="Z-INDEX: 122; LEFT: 205px; OVERFLOW: auto; WIDTH: 250px;
POSITION: absolute; TOP: 62px; HEIGHT: 185px"><asp:dat agrid
id="Datagrid1" runat="server" EnableViewState ="False" Width="200px">
<AlternatingIte mStyle BorderColor="Wh ite"
BackColor="#C0C 0FF"></AlternatingItem Style>
<Columns>
<asp:ButtonColu mn Text="Select"
CommandName="Se lect"></asp:ButtonColum n>
</Columns>
</asp:datagrid></div>
<asp:button id="btnCalculat e" style="Z-INDEX: 110; LEFT: 69px; POSITION:
absolute; TOP: 534px"
runat="server" Height="23px" Width="166px" Text="Calculate
Payment"></asp:button> 1 2000
Hi Steve,
For more information on your questions I'd recommend
reading an article on displaying data in datagrids, there
are a lot of in-depth ones on the web that are easily
accessible.
Briefly:
1) If you want to avoid a postback you'll need to
populate the textboxes using client-side javascript that
fires on the onclick() event of your button. this isn't
easily supported by asp.net server controls, but can be
accomplished.
2) Don't databind() the grid in the Page Load event - in
fact, do the binding inside a {[C#]if (!ispostback)}
condition - this way the viewstate of the datagrid
will 'remember' what was in the grid and re-display it.
If the contents of the grid change you will need to
rebind, remember to obtain the data again first though.
3) Again, you're probably rebinding to the datagrid when
the command-button is hit but there isn't any data to
bind to. Make sure that (a) if you want to rebind, get
the data first; or (b) don't rebind - and the datagrid
will load from its viewstate.
hth
alex -----Original Message----- Hi
I have a db with 2 tables that I want to bind to a grid
depending on aselection in a Dropdownlist Also I want to be able to select a row from the gris to
fill sometextboxes. The databases are static in that they will not be
updated they are justfor viewing
I have everything working but not to perfection
A few issues I am trying to solve 1) If I select a row from the select button - can I
avoid a postback and just fill the textboxes with the data in the grid row
2)It seems that I have to have the Grid.Bind() in the
Page_Load - Ithought I would only need to load the Datasets once and just re-bind to Grid????
3)The one problem I do have is that if I hit a
CommandButton thatactually needs to go to the server I lose the grid
Thanks Steve
Dim MyConnection As SqlConnection Dim DS As DataSet Dim DS2 As DataSet
Public Class DLLClass <DllImport("Pay ment.dll")> _ Public Shared Function _ CalcPaymentCH(B yVal lLOS As Integer, ByVal dCW
As Double, ByVallLTP As Integer, ByVal lHTP As Integer, ByVal dALOS As
Double, ByValdCHF As Double, ByVal dFACTOR As Double) As Double End Function
End Class
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e AsSystem.EventAr gs) Handles MyBase.Load
MyConnection = New SqlConnection(" Data
Source=localhos t;InitialCatalog=Stats; User Id=sa;Password= ;")
If Not (IsPostBack) Then ' Evals true first
time browser hitsthe page 'Put user code to initialize the page here 'BindGrid() 'Should be here ????
ddlFormula.Item s.Add("") ddlFormula.Item s.Add("Swiss 2003") ddlFormula.Item s.Add("Swiss 2004") txtCHF.Text = "5000" txtFactor.Text = "0.7" txtHTPF.Text = "2.43" txtLTPF.Text = "2.0"
txtLTPF.Visible = False txtHTPF.Visible = False lblLTPF.Visible = False lblHTPF.Visible = False
End If
BindGrid()
End Sub Private Sub ddlFormula_Sele ctedIndexChange d(ByVal
sender AsSystem.Objec t, ByVal e As System.EventArg s) Handles ddlFormula.Sel ectedIndexChang ed
If (ddlFormula.Sel ectedValue = "Swiss 2004") Then txtLTPF.Visible = True txtHTPF.Visible = True lblLTPF.Visible = True lblHTPF.Visible = True Datagrid1.DataS ource = DS2.Tables
("CHAP2004").De faultView Datagrid1.DataB ind() Else txtLTPF.Visible = False txtHTPF.Visible = False lblLTPF.Visible = False lblHTPF.Visible = False Datagrid1.DataS ource = DS.Tables
("CHAP2003").De faultView Datagrid1.DataB ind() End If
End Sub
Private Sub BindGrid()
Dim MyCommand As SqlDataAdapter
MyCommand = New SqlDataAdapter( "SELECT * FROM
CHAP2003",MyConnection ) DS = New DataSet MyCommand.Fill( DS, "CHAP2003")
MyCommand = New SqlDataAdapter( "SELECT * FROM
CHAP2004",MyConnection ) DS2 = New DataSet MyCommand.Fill( DS2, "CHAP2004")
'Datagrid1.Data Source = DS.Tables
("CHAP2003").De faultView 'Datagrid1.Data Bind()
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As
System.Object, ByVale As System.EventArg s) Handles btnCalculate.Cl ick Dim dPayment As Double If (ddlFormula.Sel ectedValue = "Swiss 2003") Then dPayment = DLLClass.CalcPa ymentCH(20, 1.5,
5, 15, 10.5,5000.0, 0.7) ElseIf (ddlFormula.Sel ectedValue = "Swiss 2004")
Then End If txtPayment.Text = Str(dPayment) End Sub Private Sub Datagrid1_Selec tedIndexChanged (ByVal
sender As Object,ByVal e As System.EventArg s) Handles
Datagrid1.Selec tedIndexChanged txtDRG.Text = Datagrid1.Selec tedItem.Cells
(1).Text.ToStri ng() txtWT.Text = Datagrid1.Selec tedItem.Cells
(2).Text.ToStri ng() txtALOS.Text = Datagrid1.Selec tedItem.Cells
(3).Text.ToStri ng() txtHTP1.Text = Datagrid1.Selec tedItem.Cells
(4).Text.ToStri ng() txtLTP.Text = Datagrid1.Selec tedItem.Cells
(5).Text.ToStri ng() End Sub End Class
<div style="Z-INDEX: 122; LEFT: 205px; OVERFLOW: auto;
WIDTH: 250px;POSITION: absolute; TOP: 62px; HEIGHT:
185px"><asp:dat agridid="Datagrid 1" runat="server" EnableViewState ="False"
Width="200px"> <AlternatingIte mStyle BorderColor="Wh ite" BackColor="#C0 C0FF"></AlternatingItem Style> <Columns> <asp:ButtonColu mn Text="Select" CommandName="S elect"></asp:ButtonColum n> </Columns> </asp:datagrid></div>
<asp:button id="btnCalculat e" style="Z-INDEX: 110; LEFT:
69px; POSITION: absolute; TOP: 534px" runat="server" Height="23px" Width="166px"
Text="CalculatePayment"></asp:button> . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shiva |
last post by:
Hi,
My (main)form has a subform that contains the details of the mainform. The
default view of the mainform is 'single form', the default view of the
subform containing the details is 'Datasheet' - Datasheet displays the data
of the associated table as a grid.
I want both the mainform (the master) and the subform to be displayed as
grid. But after changing the default view of the mainform to 'datasheet',
the subform disappears...
|
by: Paul |
last post by:
Hi I have 2 data grids and several controls on a web page. The grids will
vary in size, just wondering if the lower grid could be covered by part of
the upper grid depending on its size or is there a way to dynamically shift
the lower grid so it appears just below the upper grid?
Thanks.
--
Paul G
Software engineer.
|
by: John Wilson |
last post by:
My app produces some long datatables to display in a grid. So I put them in
a div so users can scroll. But the grid headers scroll out of view. I would
like to stop them doing this. Can I fix them in place at the top of the div?
--
John Wilson
|
by: thf |
last post by:
Hi, I wish to know how to display a collection of object which is a
property in another object in a data grid in VB.Net.
For example, I'm displaying a collection of vendor objects (in
ArrayList) in a data grid, while I wish to display the products
supplied by the vendor (which appears as a collection of product
objects in the vendor object property) in another grid.
I wish to know how can I accomplish such task. I used data...
|
by: marty |
last post by:
Hi,
Is there a top-10 of available grids specialized for display performance?
I'm searching a grid that can enable data display at rate such as 10
updates within a seconds (for something like 100 cells) and support
users clic concurrently.
Thank you!
Marty
| |
by: G .Net |
last post by:
Hi
Can anybody help with the following?
I have a datagrid which has a dataview of a datatable in a dataset as a
view. I can add new rows to the grid, however I'm puzzled as to how to pass
these changes to the database i.e. if I simple use Update on the table, the
rows I've added to the grid aren't written to the database.
Can anybody help?
|
by: tomcarr1 |
last post by:
I have an ASP.net webform with a datagrid on it.
I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "
The rest of the code in Sub Page_Load is
OleDbDataAdapter1.Fill(DsCategories1)
|
by: OfficeDummy |
last post by:
Hi, everyone!
Like I mentioned in the thread title, I need to copy&paste data between different workbooks, and it works fine. However, when the data has been copied to the destination workbook, the grid disappears.
Why, and how can I get it back?
Thanks a lot in advance!
Best,
OfficeDummy
|
by: manjeetgrang |
last post by:
I am doing editing with datagrid. all records displays in the datagrid and usrer has to select the record to edit and selected records goes to a form and changes can be made there.
but when i display the data in grid it comes good and when i navigate in the grid (say moves to 2nd record from first ), data of couple of fields of first record disappears and if i refresh the grid(the ADODC and Data grid) it gives me a message as
Binding...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |