473,406 Members | 2,371 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,406 software developers and data experts.

Bind Grid / Postback Problem

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("Payment.dll")> _
Public Shared Function _
CalcPaymentCH(ByVal 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.EventArgs) Handles MyBase.Load

MyConnection = New SqlConnection("Data Source=localhost;Initial
Catalog=Stats;User 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.Items.Add("")
ddlFormula.Items.Add("Swiss 2003")
ddlFormula.Items.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_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlFormula.SelectedIndexChanged

If (ddlFormula.SelectedValue = "Swiss 2004") Then
txtLTPF.Visible = True
txtHTPF.Visible = True
lblLTPF.Visible = True
lblHTPF.Visible = True
Datagrid1.DataSource = DS2.Tables("CHAP2004").DefaultView
Datagrid1.DataBind()
Else
txtLTPF.Visible = False
txtHTPF.Visible = False
lblLTPF.Visible = False
lblHTPF.Visible = False
Datagrid1.DataSource = DS.Tables("CHAP2003").DefaultView
Datagrid1.DataBind()
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.DataSource = DS.Tables("CHAP2003").DefaultView
'Datagrid1.DataBind()

End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnCalculate.Click
Dim dPayment As Double
If (ddlFormula.SelectedValue = "Swiss 2003") Then
dPayment = DLLClass.CalcPaymentCH(20, 1.5, 5, 15, 10.5,
5000.0, 0.7)
ElseIf (ddlFormula.SelectedValue = "Swiss 2004") Then

End If
txtPayment.Text = Str(dPayment)
End Sub

Private Sub Datagrid1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Datagrid1.SelectedIndexChanged
txtDRG.Text = Datagrid1.SelectedItem.Cells(1).Text.ToString()
txtWT.Text = Datagrid1.SelectedItem.Cells(2).Text.ToString()
txtALOS.Text = Datagrid1.SelectedItem.Cells(3).Text.ToString()
txtHTP1.Text = Datagrid1.SelectedItem.Cells(4).Text.ToString()
txtLTP.Text = Datagrid1.SelectedItem.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:datagrid
id="Datagrid1" runat="server" EnableViewState="False" Width="200px">
<AlternatingItemStyle BorderColor="White"
BackColor="#C0C0FF"></AlternatingItemStyle>
<Columns>
<asp:ButtonColumn Text="Select"
CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:datagrid></div>

<asp:button id="btnCalculate" style="Z-INDEX: 110; LEFT: 69px; POSITION:
absolute; TOP: 534px"
runat="server" Height="23px" Width="166px" Text="Calculate
Payment"></asp:button>

Nov 17 '05 #1
0 1389

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yaniv abo | last post by:
Hello. How can I bind a list of objects to a DataGird? I have a custom collection of Customer class
2
by: Kenneth | last post by:
Hi, I want to make sure I got the easiest way on how to bind a grid's datasource to a datatable. I've made an in-memory datatable Dim dtTotal As DataTable Dim drow As DataRow dtTotal = New...
1
by: mr2_93 | last post by:
Hi All, I am new to ASP.NET and I am looking for help with the dropdownlist data control. I wonder if someone could show me how to past the SelectedValue of a data-bind dropdownlist to...
0
by: Kevin | last post by:
Hi my name is Kevin can someone help me with the objectdatasource, when binding bussines objects to it ? i can normally bind them to a grid and detail grid but the problem remains that when the...
3
by: vineetbatta | last post by:
I have Custom Data class which stores data about single customer and then i store that customer objects in arraylist as shown below. Customer custdata = null; // Custom Data class for 1 customer...
2
by: Taha | last post by:
Hi All Can You please Explain To Me How Bind XML Data From WebService To Grid In Vb.Net Thanks
0
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a...
2
by: Roger Frei | last post by:
Hello ng, I have a datagrid that is bound to a datasource. That works good so far. Now I want to add another column to my grid dynamically. That also works good until the first postback. The...
3
by: Kurt Jakobsen | last post by:
Hello, Sorry for putting this problem back on the list. I had it previously under another title that now does not describe the real problem. Hopefully the new title will trigger someone that has had...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.