473,386 Members | 1,785 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.

Grid Disappears (WebForm)

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

MyConnection = New SqlConnection("Data Source=localhost;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.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 AsSystem.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, ByVale 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:datagridid="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="CalculatePayment"></asp:button>

.

Nov 18 '05 #2

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

Similar topics

1
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...
6
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...
10
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...
1
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)...
5
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...
4
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...
5
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...
2
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,...
3
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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: 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
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.