tags:

views:

23

answers:

2

i want to show a grid in center on pageload and when i click on select button on grid it should shift to right of page....

now m using 2 grid to show it on center and on right...

+1  A: 

To change position from server side:

if grid is present in DIV or any other HTML tag add runat="sever" to that then after button is pressed access the style property of that div & get the Left or Right or Top or any other position-attribute assign the desired position to that attribute & update the updatepanel in which that div is present.

<Markup>
<asp:updatepanel id="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="griddiv" runat="server">
<asp:grid id="maingrid" runat="server"/>
</div>
</ContentTemplate>
</asp:updatepane>


protected void btn_Click(object sender,Eventargs es)
{

griddiv.style.attribute("top","new pos");
//This is done as a precaution
maingrid.DataSource = datatable;
maingrid.Rebind();
up1.Update();
}
KhanZeeshan
error :::Error 1 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a definition for 'style' and no extension method 'style' accepting a first argument of type i have add the attribute runat="server" to div
Sheetal Inani
why the error is coming?????????????///
Sheetal Inani
what type of HTML control are you using, i mean is the grid in DIV or TABLE?
KhanZeeshan
also which framework are you using?
KhanZeeshan
check out this link: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol_properties(v=VS.71).aspx
KhanZeeshan
i m using div... the frame work is 3.5
Sheetal Inani
then it should have STYLE property, I have used DIV, TD myself.
KhanZeeshan
thax... but the correct code is griddiv.Style.Add("float","right");
Sheetal Inani
how to set it in the font again??? m using the code gridview.Style.remove("Float"); gridview.Style.Add("Text-align","center");
Sheetal Inani
do you mean the text in GridColumns?
KhanZeeshan
no the whole grid... I want that on some button click the grid should come in center
Sheetal Inani
if the gird is in div then div has a propert of align set its value to center.
KhanZeeshan
i havwe done that gridview.Style.Add("Text-align","center"); but its not working... i have remove the float right by gridview.Style.remove("Float");
Sheetal Inani
what you have done is for TEXT like griddiv.Style.Add("align","center");
KhanZeeshan
i think you are misunderstanding me, i'm saying ALIGN not TEXT-ALIGN. These are two different things. The text-align: center is used to center the content within the div. It would be the same as p align=" center" . The div align=" center" is used to center the entire block element that it is assigned to. It would be the same as table align=" center" .
KhanZeeshan
thax.... i was using text-align..... now its working with using only align.... thax alot
Sheetal Inani
you can also achieve this by applying padding, but thats a bad way of doing it.
KhanZeeshan
yaaa... but this works fine
Sheetal Inani
good. your welcome.
KhanZeeshan
A: 

if grid is present in div give id and property runat=server then on select button give this coding... griddiv.Style.Add("float","right");

Sheetal Inani