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)
-   -   Postback does not maintain sort direction Image? (http://www.velocityreviews.com/forums/t762810-postback-does-not-maintain-sort-direction-image.html)

rockdale 06-08-2006 02:50 PM

Postback does not maintain sort direction Image?
 
Hi, All:
I dynamic add an arrow up/down image in OnItemDataBound event for my
datagrid, it works fine. But I have another textbox which trigger
postback and doing something, after this event get executed, I lost the
image but the datagrid maintain the same sort order. Should the
datagrid remain what it looks like (with the riget arrow up/down image)
before the postback caused by the textbox?

I tried to get the datagrid header in the text postback event
(OnChanged), but I do not know how to get the datagrid header. I do not
want to rebind the datagrid in the textbox OnChanged event.

Or should I use other method to show the sort direction image?


private void dgrid_OnItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//Sorting Image
if(e.Item.ItemType == ListItemType.Header)
{
foreach(TableCell tc in e.Item.Cells)
{
if(tc.Controls.Count > 0)
{
try
{
LinkButton lkbSortCol =
(System.Web.UI.WebControls.LinkButton)tc.Controls[0];
if(lkbSortCol.CommandArgument.ToString().Equals(dg rid.Attributes["SortExpression"]))
{
System.Web.UI.WebControls.Image imgSort = new
System.Web.UI.WebControls.Image();
if(dgrid.Attributes["SortDirection"].Equals("DESC"))
{
imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
}
else
{
imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
}


tc.Controls.AddAt(1, imgSort);
}
}
catch(Exception ex)
{
Trace.Write(ex.Message);
}
}//end if tc.controls.count > 0
}//end for

} //end item type

}


Balasubramanian Ramanathan 06-14-2006 05:26 PM

Re: Postback does not maintain sort direction Image?
 
I had the same problem and adding the image in prerender event of the
gridview/datagrid solved the problem..

"rockdale" <rockdale.green@gmail.com> wrote in message
news:1149778230.386804.302020@f6g2000cwb.googlegro ups.com...
> Hi, All:
> I dynamic add an arrow up/down image in OnItemDataBound event for my
> datagrid, it works fine. But I have another textbox which trigger
> postback and doing something, after this event get executed, I lost the
> image but the datagrid maintain the same sort order. Should the
> datagrid remain what it looks like (with the riget arrow up/down image)
> before the postback caused by the textbox?
>
> I tried to get the datagrid header in the text postback event
> (OnChanged), but I do not know how to get the datagrid header. I do not
> want to rebind the datagrid in the textbox OnChanged event.
>
> Or should I use other method to show the sort direction image?
>
>
> private void dgrid_OnItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> //Sorting Image
> if(e.Item.ItemType == ListItemType.Header)
> {
> foreach(TableCell tc in e.Item.Cells)
> {
> if(tc.Controls.Count > 0)
> {
> try
> {
> LinkButton lkbSortCol =
> (System.Web.UI.WebControls.LinkButton)tc.Controls[0];
> if(lkbSortCol.CommandArgument.ToString().Equals(dg rid.Attributes["SortExpression"]))
> {
> System.Web.UI.WebControls.Image imgSort = new
> System.Web.UI.WebControls.Image();
> if(dgrid.Attributes["SortDirection"].Equals("DESC"))
> {
> imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
> }
> else
> {
> imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
> }
>
>
> tc.Controls.AddAt(1, imgSort);
> }
> }
> catch(Exception ex)
> {
> Trace.Write(ex.Message);
> }
> }//end if tc.controls.count > 0
> }//end for
>
> } //end item type
>
> }
>




rockdale 06-19-2006 07:00 PM

Re: Postback does not maintain sort direction Image?
 
Thanks for your suggestion, But how can I get the DatagridHeader in
preRender event?
Thanks a lot

Balasubramanian Ramanathan wrote:
> I had the same problem and adding the image in prerender event of the
> gridview/datagrid solved the problem..
>
> "rockdale" <rockdale.green@gmail.com> wrote in message
> news:1149778230.386804.302020@f6g2000cwb.googlegro ups.com...
> > Hi, All:
> > I dynamic add an arrow up/down image in OnItemDataBound event for my
> > datagrid, it works fine. But I have another textbox which trigger
> > postback and doing something, after this event get executed, I lost the
> > image but the datagrid maintain the same sort order. Should the
> > datagrid remain what it looks like (with the riget arrow up/down image)
> > before the postback caused by the textbox?
> >
> > I tried to get the datagrid header in the text postback event
> > (OnChanged), but I do not know how to get the datagrid header. I do not
> > want to rebind the datagrid in the textbox OnChanged event.
> >
> > Or should I use other method to show the sort direction image?
> >
> >
> > private void dgrid_OnItemDataBound(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > //Sorting Image
> > if(e.Item.ItemType == ListItemType.Header)
> > {
> > foreach(TableCell tc in e.Item.Cells)
> > {
> > if(tc.Controls.Count > 0)
> > {
> > try
> > {
> > LinkButton lkbSortCol =
> > (System.Web.UI.WebControls.LinkButton)tc.Controls[0];
> > if(lkbSortCol.CommandArgument.ToString().Equals(dg rid.Attributes["SortExpression"]))
> > {
> > System.Web.UI.WebControls.Image imgSort = new
> > System.Web.UI.WebControls.Image();
> > if(dgrid.Attributes["SortDirection"].Equals("DESC"))
> > {
> > imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
> > }
> > else
> > {
> > imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
> > }
> >
> >
> > tc.Controls.AddAt(1, imgSort);
> > }
> > }
> > catch(Exception ex)
> > {
> > Trace.Write(ex.Message);
> > }
> > }//end if tc.controls.count > 0
> > }//end for
> >
> > } //end item type
> >
> > }
> >



Balasubramanian Ramanathan 06-21-2006 10:16 AM

Re: Postback does not maintain sort direction Image?
 
There is no trick in that just use the headerrow property of the gridview

GridViewRow hdr = Grid.HeaderRow;

"rockdale" <rockdale.green@gmail.com> wrote in message
news:1150743629.206602.80820@y41g2000cwy.googlegro ups.com...
> Thanks for your suggestion, But how can I get the DatagridHeader in
> preRender event?
> Thanks a lot
>
> Balasubramanian Ramanathan wrote:
>> I had the same problem and adding the image in prerender event of the
>> gridview/datagrid solved the problem..
>>
>> "rockdale" <rockdale.green@gmail.com> wrote in message
>> news:1149778230.386804.302020@f6g2000cwb.googlegro ups.com...
>> > Hi, All:
>> > I dynamic add an arrow up/down image in OnItemDataBound event for my
>> > datagrid, it works fine. But I have another textbox which trigger
>> > postback and doing something, after this event get executed, I lost the
>> > image but the datagrid maintain the same sort order. Should the
>> > datagrid remain what it looks like (with the riget arrow up/down image)
>> > before the postback caused by the textbox?
>> >
>> > I tried to get the datagrid header in the text postback event
>> > (OnChanged), but I do not know how to get the datagrid header. I do not
>> > want to rebind the datagrid in the textbox OnChanged event.
>> >
>> > Or should I use other method to show the sort direction image?
>> >
>> >
>> > private void dgrid_OnItemDataBound(object sender,
>> > System.Web.UI.WebControls.DataGridItemEventArgs e)
>> > {
>> > //Sorting Image
>> > if(e.Item.ItemType == ListItemType.Header)
>> > {
>> > foreach(TableCell tc in e.Item.Cells)
>> > {
>> > if(tc.Controls.Count > 0)
>> > {
>> > try
>> > {
>> > LinkButton lkbSortCol =
>> > (System.Web.UI.WebControls.LinkButton)tc.Controls[0];
>> > if(lkbSortCol.CommandArgument.ToString().Equals(dg rid.Attributes["SortExpression"]))
>> > {
>> > System.Web.UI.WebControls.Image imgSort = new
>> > System.Web.UI.WebControls.Image();
>> > if(dgrid.Attributes["SortDirection"].Equals("DESC"))
>> > {
>> > imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
>> > }
>> > else
>> > {
>> > imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
>> > }
>> >
>> >
>> > tc.Controls.AddAt(1, imgSort);
>> > }
>> > }
>> > catch(Exception ex)
>> > {
>> > Trace.Write(ex.Message);
>> > }
>> > }//end if tc.controls.count > 0
>> > }//end for
>> >
>> > } //end item type
>> >
>> > }
>> >

>




rockdale 06-21-2006 06:30 PM

Re: Postback does not maintain sort direction Image?
 
Thanks, but I am not using GridView.
Anyway, I move my code to OnItemCreate event and get what I wanted.



Balasubramanian Ramanathan wrote:
> There is no trick in that just use the headerrow property of the gridview
>
> GridViewRow hdr = Grid.HeaderRow;
>
> "rockdale" <rockdale.green@gmail.com> wrote in message
> news:1150743629.206602.80820@y41g2000cwy.googlegro ups.com...
> > Thanks for your suggestion, But how can I get the DatagridHeader in
> > preRender event?
> > Thanks a lot
> >
> > Balasubramanian Ramanathan wrote:
> >> I had the same problem and adding the image in prerender event of the
> >> gridview/datagrid solved the problem..
> >>
> >> "rockdale" <rockdale.green@gmail.com> wrote in message
> >> news:1149778230.386804.302020@f6g2000cwb.googlegro ups.com...
> >> > Hi, All:
> >> > I dynamic add an arrow up/down image in OnItemDataBound event for my
> >> > datagrid, it works fine. But I have another textbox which trigger
> >> > postback and doing something, after this event get executed, I lost the
> >> > image but the datagrid maintain the same sort order. Should the
> >> > datagrid remain what it looks like (with the riget arrow up/down image)
> >> > before the postback caused by the textbox?
> >> >
> >> > I tried to get the datagrid header in the text postback event
> >> > (OnChanged), but I do not know how to get the datagrid header. I do not
> >> > want to rebind the datagrid in the textbox OnChanged event.
> >> >
> >> > Or should I use other method to show the sort direction image?
> >> >
> >> >
> >> > private void dgrid_OnItemDataBound(object sender,
> >> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> >> > {
> >> > //Sorting Image
> >> > if(e.Item.ItemType == ListItemType.Header)
> >> > {
> >> > foreach(TableCell tc in e.Item.Cells)
> >> > {
> >> > if(tc.Controls.Count > 0)
> >> > {
> >> > try
> >> > {
> >> > LinkButton lkbSortCol =
> >> > (System.Web.UI.WebControls.LinkButton)tc.Controls[0];
> >> > if(lkbSortCol.CommandArgument.ToString().Equals(dg rid.Attributes["SortExpression"]))
> >> > {
> >> > System.Web.UI.WebControls.Image imgSort = new
> >> > System.Web.UI.WebControls.Image();
> >> > if(dgrid.Attributes["SortDirection"].Equals("DESC"))
> >> > {
> >> > imgSort.ImageUrl = Server.MapPath("Images/sort_desc.gif");
> >> > }
> >> > else
> >> > {
> >> > imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
> >> > }
> >> >
> >> >
> >> > tc.Controls.AddAt(1, imgSort);
> >> > }
> >> > }
> >> > catch(Exception ex)
> >> > {
> >> > Trace.Write(ex.Message);
> >> > }
> >> > }//end if tc.controls.count > 0
> >> > }//end for
> >> >
> >> > } //end item type
> >> >
> >> > }
> >> >

> >




All times are GMT. The time now is 04:09 AM.

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