473,779 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid Postback issues

Hello all,

I have a Datagrid on a page. 1 column is a template column with a checkbox
(unbound). The rest of the columns are databound that are added
programatically .

If in the Page_Load I do:
If IsPostBack Then

else

end if

BIND DATA HERE

Then the grid displays correctly every time but the checkboxes are always
cleared so I can never check them.

If I do this...

If IsPostBack Then

else
BIND DATA HERE
end if

The grid posts back the first time but the second pass the grid is empty!

Any clues to what I am doing wrong?

Thanks in advance,
Bob
Nov 18 '05 #1
2 1574
are you using the checkbox attribute AutoPostBack = True
make it False.

if it is required to make true then set the code
If IsPostBack Then else
BIND DATA HERE
end if

Regards
Ather Ali Shaikh

"Bob Trabucco" <bo**@ccc-soft.com> wrote in message
news:#8******** ******@TK2MSFTN GP11.phx.gbl... Hello all,

I have a Datagrid on a page. 1 column is a template column with a checkbox (unbound). The rest of the columns are databound that are added
programatically .

If in the Page_Load I do:
If IsPostBack Then

else

end if

BIND DATA HERE

Then the grid displays correctly every time but the checkboxes are always
cleared so I can never check them.

If I do this...

If IsPostBack Then

else
BIND DATA HERE
end if

The grid posts back the first time but the second pass the grid is empty!

Any clues to what I am doing wrong?

Thanks in advance,
Bob

Nov 18 '05 #2
Thanks for the response but it still isn't working correctly... More
details....

Grid Definition...

<asp:datagrid id="dgEquipment " tabIndex="50" runat="server"
Width="664px" BackColor="Whit e" BorderColor="#C CCCCC"
ToolTip="Equipm ent at this location" EnableViewState ="true"
PageSize="9999" CellPadding="3"
AutoGenerateCol umns="False" BorderWidth="1p x" BorderStyle="No ne">
<SelectedItemSt yle Font-Size="Smaller" Font-Names="Arial"
Font-Bold="True" ForeColor="Whit e" BackColor="#669 999"></SelectedItemSty le>
<EditItemStyl e Font-Size="Larger" Font-Names="Arial"></EditItemStyle>
<AlternatingIte mStyle Font-Size="XX-Small"
Font-Names="Arial"></AlternatingItem Style>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial"
ForeColor="#000 066"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True"
ForeColor="Blac k" BackColor="#D3F 2FE"></HeaderStyle>
<FooterStyle ForeColor="#000 066" BackColor="Whit e"></FooterStyle>
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:CheckBox runat="server" AutoPostBack="f alse"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle Font-Size="Smaller" Font-Names="Arial"
HorizontalAlign ="Left" ForeColor="#000 066"
BackColor="Whit e" Mode="NumericPa ges"></PagerStyle>
</asp:datagrid>

Private Sub InitGrid()

' Add the columns programmaticall y since we will eventually let the
users define which columns are displayed...
If dgEquipment.Col umns.Count <= 1 Then

Dim col As BoundColumn

col = New BoundColumn
col.HeaderText = "Counter"
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Left
col.DataField = "Counter"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
col.Visible = False
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderText = "Make"
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Left
col.DataField = "MFG"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Left
col.HeaderText = "Model"
col.DataField = "MODEL"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Left
col.HeaderText = "Serial #"
col.DataField = "SERIAL"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Right
col.HeaderText = "Install Date"
col.DataField = "INSTALL"
col.DataFormatS tring = "{0:d}"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Right
col.HeaderText = "Warranty"
col.DataField = "Warranty"
col.DataFormatS tring = "{0:d}"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

col = New BoundColumn
col.HeaderStyle .HorizontalAlig n = HorizontalAlign .Center
col.ItemStyle.H orizontalAlign = HorizontalAlign .Right
col.HeaderText = "Agreement #"
col.DataField = "SerAgrNo"
col.ItemStyle.F ont.Name = "Arial"
col.ItemStyle.F ont.Size = System.Web.UI.W ebControls.Font Unit.XXSmall
dgEquipment.Col umns.Add(col)

End If
End Sub

Private Sub LoadGrid()

' Equipment Grid

Dim equip As New clsEquip
equip.InitDBCon nection(Session ("ConnectionStr ing"))
equip.Load(Sess ion("CustNo"), Session("LocNo" ))
dgEquipment.Dat aSource = equip

DataBind()

equip = Nothing

End Sub
With the following the grid displays all the data and the checkbox
correctly. But when I click any button on the screen any checks I have made
are cleared so I can't check and see what the user checked....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If IsPostBack Then

' Do some stuff here

Else

' Do other stuff here

End If

InitGrid()
LoadGrid()

Exit Sub
With this one the second time around the grid is empty except for the
checkbox column...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If IsPostBack Then

' Do some stuff here

Else

' Do other stuff here
InitGrid()
LoadGrid()
End If
Exit Sub
I am sure I am just missing something. Thanks in advance!

Bob

"Ather Ali Shaikh" <at*******@eint elligencesoft.c om> wrote in message
news:OD******** *****@tk2msftng p13.phx.gbl...
are you using the checkbox attribute AutoPostBack = True
make it False.

if it is required to make true then set the code
If IsPostBack Then

else
> BIND DATA HERE
end if


Regards
Ather Ali Shaikh

"Bob Trabucco" <bo**@ccc-soft.com> wrote in message
news:#8******** ******@TK2MSFTN GP11.phx.gbl...
Hello all,

I have a Datagrid on a page. 1 column is a template column with a

checkbox
(unbound). The rest of the columns are databound that are added
programatically .

If in the Page_Load I do:
If IsPostBack Then

else

end if

BIND DATA HERE

Then the grid displays correctly every time but the checkboxes are always cleared so I can never check them.

If I do this...

If IsPostBack Then

else
BIND DATA HERE
end if

The grid posts back the first time but the second pass the grid is empty!
Any clues to what I am doing wrong?

Thanks in advance,
Bob


Nov 18 '05 #3

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

Similar topics

2
945
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
7
3556
by: A.M | last post by:
Hi, I want to refresh my DataGrid data on every postback. I have following code in Page_Load event, but after first page load, the DataGrid never gets refresh. Here is the code i have in Page_load (it works at first page_load): Dim DS As DataSet Dim MyConnection As System.Data.SqlClient.SqlConnection
1
3434
by: Michelle Stone | last post by:
Hi all. I have an empty datagrid on my web form. And I add BoundDataColumn(s) to it through code. But after each postback, the columns and rows disappear. As a workabout, I tried to rebind the datagrid to the dataset (stored in a session variable) on the PageLoad function which works fine. But my datagrid has a button-column called EDIT which is supposed to execute some code. But during the postback,
2
2402
by: Bruce W.1 | last post by:
There's something I can't figure out. I added some javascript behavior to my datagrid, just like in this article, except in C# instead of VB: http://www.dotnetbips.com/displayarticle.aspx?id=205 If I bind the datagrid to the dataset at all times, whether Postback or not, then everything works fine. However if I only bind it when Page is not Postback (just like
2
5929
by: Fluxray | last post by:
--Background: I have a webform including a datagrid. The datagrid is using template. Its ItemTemplate is used to display a look-up-table with labels. its EditItemTemplate is used to edit a row in the look-up-table with textboxes. I have a linkbutton in each row (causevalidation = false) named 'Edit' to post the page back such that the page is switch from display mode to edit mode (labels -> textboxes for the row to be edited), and the...
2
2220
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of the 26 letters of the alphabet as hyperlinks which the users then click to return records beginning with that letter, displayed in a DataGrid. The first column of the DataGrid contains a LinkButton which, when clicked, calls the Delete method of...
2
1685
by: Jim Bancroft | last post by:
This may be a no-brainer, but I'm sure I follow what's happening here... I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop through the DataGridItems unless I rebind my DataGrid. By "can't loop," I mean it's a mighty quick run through-- zero iterations. I was wondering...do I have to rebind on postbacks? If so, what happens if I bind the DataGrid to a different set of...
1
1638
by: wh1974 | last post by:
I'm not sure if i'm heading in the right direction so would appreciate any comments on what I'm trying to do. Basically I have a DataGrid on a page which has columns whose width's I set in the DataGrid's ItemCreated event and which need to be remembered after a postback. I bind to the DataGrid in the Page_Load event when PostBack is false. The DataGrid displays the data horizontally so I set the RepeatColumns
2
5867
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to use template columns as they seem to be a little difficult to create at runtime. Any assistance would be very greatly appreciated. private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if...
2
7210
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in ASPX page <asp:DataGrid id="MyGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" runat="server" EnableViewState="True"> <Columns>
0
9471
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,...
0
10302
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, 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...
0
10136
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 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...
0
8958
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, 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...
1
7478
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
bsmnconsultancy
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...

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.