Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid Postback issues

Reply
Thread Tools

Datagrid Postback issues

 
 
Bob Trabucco
Guest
Posts: n/a
 
      01-16-2004
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


 
Reply With Quote
 
 
 
 
Ather Ali Shaikh
Guest
Posts: n/a
 
      01-17-2004
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Bob Trabucco
Guest
Posts: n/a
 
      01-19-2004
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="White" BorderColor="#CCCCCC"
ToolTip="Equipment at this location" EnableViewState="true"
PageSize="9999" CellPadding="3"
AutoGenerateColumns="False" BorderWidth="1px" BorderStyle="None">
<SelectedItemStyle Font-Size="Smaller" Font-Names="Arial"
Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
<EditItemStyle Font-Size="Larger" Font-Names="Arial"></EditItemStyle>
<AlternatingItemStyle Font-Size="XX-Small"
Font-Names="Arial"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial"
ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True"
ForeColor="Black" BackColor="#D3F2FE"></HeaderStyle>
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" AutoPostBack="false"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="Smaller" Font-Names="Arial"
HorizontalAlign="Left" ForeColor="#000066"
BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

Private Sub InitGrid()

' Add the columns programmatically since we will eventually let the
users define which columns are displayed...
If dgEquipment.Columns.Count <= 1 Then

Dim col As BoundColumn

col = New BoundColumn
col.HeaderText = "Counter"
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col.DataField = "Counter"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
col.Visible = False
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderText = "Make"
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col.DataField = "MFG"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col.HeaderText = "Model"
col.DataField = "MODEL"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col.HeaderText = "Serial #"
col.DataField = "SERIAL"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Right
col.HeaderText = "Install Date"
col.DataField = "INSTALL"
col.DataFormatString = "{0:d}"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Right
col.HeaderText = "Warranty"
col.DataField = "Warranty"
col.DataFormatString = "{0:d}"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

col = New BoundColumn
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col.ItemStyle.HorizontalAlign = HorizontalAlign.Right
col.HeaderText = "Agreement #"
col.DataField = "SerAgrNo"
col.ItemStyle.Font.Name = "Arial"
col.ItemStyle.Font.Size = System.Web.UI.WebControls.FontUnit.XXSmall
dgEquipment.Columns.Add(col)

End If
End Sub

Private Sub LoadGrid()

' Equipment Grid

Dim equip As New clsEquip
equip.InitDBConnection(Session("ConnectionString") )
equip.Load(Session("CustNo"), Session("LocNo"))
dgEquipment.DataSource = 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.EventArgs) 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.EventArgs) 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ShowDialogModal postback on close (this is not related to multiple dialogs opening upon postback) Jacky Chau ASP .Net 2 06-08-2005 05:49 PM
Can I raise a postback ? Session variable only visible after postback. Please help gce ASP .Net 2 05-08-2005 05:55 AM
Postback not being set to True on first postback =?Utf-8?B?Q2hhZA==?= ASP .Net 2 04-04-2005 06:17 PM
effecting postback without auto postback controls Psych971 ASP .Net 5 12-17-2004 08:53 PM
Datagrid Postback issues Bob Trabucco ASP .Net 2 01-19-2004 02:19 PM



Advertisments