Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   Datagrid SelectedIndexChanged Problem in CodeBehind (http://www.velocityreviews.com/forums/t759336-datagrid-selectedindexchanged-problem-in-codebehind.html)

Brian K. Williams 08-14-2003 10:33 PM

Datagrid SelectedIndexChanged Problem in CodeBehind
 
I am attempting to use the SelectedIndexChanged to detect when a row has
been selected. I have seen many examples where they are writing all the code
on the ASPX page.

When I attempt to use the SelectedIndexChanged on the Code Behind it never
fires.

////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////

The CodeBehind:
public void dbGridPlayers_SelectedIndexChanged(object sender,
System.EventArgs e){

playerInfo.Text = dbGridPlayers.SelectedItem.Cells[1].Text;

}

////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////

The APSX Code:

<asp:DataGrid id="dbGridPlayers" runat="server"
OnSelectedIndexChanged="dbGridPlayers_SelectedInde xChanged"
DataKeyField="PlayerID" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="0"
Width="100%">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066" CssClass="ItemRow"
Font-Name="Arial" Font-Size="9"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#006699" Font-Name="Arial" Font-Size="10"></HeaderStyle>
<FooterStyle ForeColor="#000066"
BackColor="White"></FooterStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066"
BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>


Thanks for any help.
Brian K. Williams



Jos 08-15-2003 07:49 AM

Re: Datagrid SelectedIndexChanged Problem in CodeBehind
 
Brian K. Williams wrote:
> I am attempting to use the SelectedIndexChanged to detect when a row
> has been selected. I have seen many examples where they are writing
> all the code on the ASPX page.
>
> When I attempt to use the SelectedIndexChanged on the Code Behind it
> never fires.
>
>

////////////////////////////////////////////////////////////////////////////
> //////////////////////////////////////
>
> The CodeBehind:
> public void dbGridPlayers_SelectedIndexChanged(object sender,
> System.EventArgs e){
>
> playerInfo.Text = dbGridPlayers.SelectedItem.Cells[1].Text;
>
> }
>
>

////////////////////////////////////////////////////////////////////////////
> //////////////////////////////////////
>
> The APSX Code:
>
> <asp:DataGrid id="dbGridPlayers" runat="server"
> OnSelectedIndexChanged="dbGridPlayers_SelectedInde xChanged"
> DataKeyField="PlayerID" BorderColor="#CCCCCC" BorderStyle="None"
> BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="0"
> Width="100%">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#669999"></SelectedItemStyle>
> <ItemStyle ForeColor="#000066" CssClass="ItemRow"
> Font-Name="Arial" Font-Size="9"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#006699" Font-Name="Arial" Font-Size="10"></HeaderStyle>
> <FooterStyle ForeColor="#000066"
> BackColor="White"></FooterStyle>
> <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> BackColor="White" Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
>
>
> Thanks for any help.
> Brian K. Williams


You're supposed to have a Button or LinkButton in your grid with
CommandName="Select".
Clicking this button will fire the SelectedIndexChanged event.

--

Jos Branders



Jim Mitchell 08-16-2003 06:23 PM

Re: Datagrid SelectedIndexChanged Problem in CodeBehind
 
Are you building the column at design time or run time?

"Brian K. Williams" <williamsb@adelphia.net> wrote in message
news:%23EFa5PrYDHA.2620@TK2MSFTNGP09.phx.gbl...
> I am attempting to use the SelectedIndexChanged to detect when a row has
> been selected. I have seen many examples where they are writing all the

code
> on the ASPX page.
>
> When I attempt to use the SelectedIndexChanged on the Code Behind it never
> fires.
>
>

////////////////////////////////////////////////////////////////////////////
> //////////////////////////////////////
>
> The CodeBehind:
> public void dbGridPlayers_SelectedIndexChanged(object sender,
> System.EventArgs e){
>
> playerInfo.Text = dbGridPlayers.SelectedItem.Cells[1].Text;
>
> }
>
>

////////////////////////////////////////////////////////////////////////////
> //////////////////////////////////////
>
> The APSX Code:
>
> <asp:DataGrid id="dbGridPlayers" runat="server"
> OnSelectedIndexChanged="dbGridPlayers_SelectedInde xChanged"
> DataKeyField="PlayerID" BorderColor="#CCCCCC" BorderStyle="None"
> BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="0"
> Width="100%">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#669999"></SelectedItemStyle>
> <ItemStyle ForeColor="#000066" CssClass="ItemRow"
> Font-Name="Arial" Font-Size="9"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#006699" Font-Name="Arial" Font-Size="10"></HeaderStyle>
> <FooterStyle ForeColor="#000066"
> BackColor="White"></FooterStyle>
> <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> BackColor="White" Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
>
>
> Thanks for any help.
> Brian K. Williams
>
>




Brian K. Williams 08-17-2003 06:59 AM

Re: Datagrid SelectedIndexChanged Problem in CodeBehind
 
It seems to me that if the SelectedIndexChanged event is available when the
code is in the ASPX, there must be a way to expose this event for use in a
code behind.

Thanks
Brian K. Williams


"Jos" <josnospambranders@fastmail.fm> wrote in message
news:uD3HPHwYDHA.2284@TK2MSFTNGP10.phx.gbl...
> Brian K. Williams wrote:
> > I am attempting to use the SelectedIndexChanged to detect when a row
> > has been selected. I have seen many examples where they are writing
> > all the code on the ASPX page.
> >
> > When I attempt to use the SelectedIndexChanged on the Code Behind it
> > never fires.
> >
> >

>

////////////////////////////////////////////////////////////////////////////
> > //////////////////////////////////////
> >
> > The CodeBehind:
> > public void dbGridPlayers_SelectedIndexChanged(object sender,
> > System.EventArgs e){
> >
> > playerInfo.Text = dbGridPlayers.SelectedItem.Cells[1].Text;
> >
> > }
> >
> >

>

////////////////////////////////////////////////////////////////////////////
> > //////////////////////////////////////
> >
> > The APSX Code:
> >
> > <asp:DataGrid id="dbGridPlayers" runat="server"
> > OnSelectedIndexChanged="dbGridPlayers_SelectedInde xChanged"
> > DataKeyField="PlayerID" BorderColor="#CCCCCC" BorderStyle="None"
> > BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="0"
> > Width="100%">
> > <SelectedItemStyle Font-Bold="True" ForeColor="White"
> > BackColor="#669999"></SelectedItemStyle>
> > <ItemStyle ForeColor="#000066" CssClass="ItemRow"
> > Font-Name="Arial" Font-Size="9"></ItemStyle>
> > <HeaderStyle Font-Bold="True" ForeColor="White"
> > BackColor="#006699" Font-Name="Arial" Font-Size="10"></HeaderStyle>
> > <FooterStyle ForeColor="#000066"
> > BackColor="White"></FooterStyle>
> > <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> > BackColor="White" Mode="NumericPages"></PagerStyle>
> > </asp:DataGrid>
> >
> >
> > Thanks for any help.
> > Brian K. Williams

>
> You're supposed to have a Button or LinkButton in your grid with
> CommandName="Select".
> Clicking this button will fire the SelectedIndexChanged event.
>
> --
>
> Jos Branders
>
>




Jim Mitchell 08-19-2003 03:47 AM

Re: Datagrid SelectedIndexChanged Problem in CodeBehind
 
I have had some similar trouble. My problem seemed to have something to do
with the order things were firing.....

In otherwords, on postback the pageload seemed to fire first, setting the
selected index back to 0. Then the dbGrid_SelectedIndexChanged event would
fire and show me the value in the first line.

Sorry if I am wasting your time, but do you see "RAT" in the textbox if you
use the following....

If so, the event is firing and you have a different problem.

The CodeBehind:
public void dbGridPlayers_SelectedIndexChanged(object sender,
System.EventArgs e){

playerInfo.Text = "RAT"
}



"Brian K. Williams" <williamsb@adelphia.net> wrote in message
news:ulmnlyIZDHA.2032@TK2MSFTNGP10.phx.gbl...
> Run Time...
> Could that make a difference?
>
> "Jim Mitchell" <jim_mitchell@mindspring.com> wrote in message
> news:Oy0WIQCZDHA.2308@TK2MSFTNGP12.phx.gbl...
> > Are you building the column at design time or run time?
> >
> > "Brian K. Williams" <williamsb@adelphia.net> wrote in message
> > news:%23EFa5PrYDHA.2620@TK2MSFTNGP09.phx.gbl...
> > > I am attempting to use the SelectedIndexChanged to detect when a row

has
> > > been selected. I have seen many examples where they are writing all

the
> > code
> > > on the ASPX page.
> > >
> > > When I attempt to use the SelectedIndexChanged on the Code Behind it

> never
> > > fires.
> > >
> > >

> >

>

////////////////////////////////////////////////////////////////////////////
> > > //////////////////////////////////////
> > >
> > > The CodeBehind:
> > > public void dbGridPlayers_SelectedIndexChanged(object sender,
> > > System.EventArgs e){
> > >
> > > playerInfo.Text = dbGridPlayers.SelectedItem.Cells[1].Text;
> > >
> > > }
> > >
> > >

> >

>

////////////////////////////////////////////////////////////////////////////
> > > //////////////////////////////////////
> > >
> > > The APSX Code:
> > >
> > > <asp:DataGrid id="dbGridPlayers" runat="server"
> > > OnSelectedIndexChanged="dbGridPlayers_SelectedInde xChanged"
> > > DataKeyField="PlayerID" BorderColor="#CCCCCC" BorderStyle="None"
> > > BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="0"
> > > Width="100%">
> > > <SelectedItemStyle Font-Bold="True" ForeColor="White"
> > > BackColor="#669999"></SelectedItemStyle>
> > > <ItemStyle ForeColor="#000066" CssClass="ItemRow"
> > > Font-Name="Arial" Font-Size="9"></ItemStyle>
> > > <HeaderStyle Font-Bold="True" ForeColor="White"
> > > BackColor="#006699" Font-Name="Arial" Font-Size="10"></HeaderStyle>
> > > <FooterStyle ForeColor="#000066"
> > > BackColor="White"></FooterStyle>
> > > <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> > > BackColor="White" Mode="NumericPages"></PagerStyle>
> > > </asp:DataGrid>
> > >
> > >
> > > Thanks for any help.
> > > Brian K. Williams
> > >
> > >

> >
> >

>
>





All times are GMT. The time now is 07:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.