Showing posts with label elements. Show all posts
Showing posts with label elements. Show all posts

Monday, March 26, 2012

How do I Databind to a GridView inside an Accordion Pane

I am trying to DataBind the results of a query to a GridView Control inside an Accoridon Pane. I can get the data from the elements in the Accordion Pane but I don't know how to add or bind data to them. Here is my code

ASP Code

<atlasToolkit:Accordion ID="MyAccordion" runat="server" SelectedIndex="0"
HeaderCssClass="accordionHeader" ContentCssClass="accordionContent"
FadeTransitions="true" FramesPerSecond="40" TransitionDuration="250"
AutoSize="none" >
<atlasToolkit:AccordionPane ID="AccordionRest" runat="server" >
<Header>
<a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Restricted Items</a>
</Header>
<Content><h1>Restrict SKUs</h1>
<asp:Label ID="lRestricted" runat="server" Text="This Months Restricted SKUS"></asp:Label>
<asp:GridView ID="gvRestricted" runat="server"></asp:GridView> <!-- This is the GridView I want to DataBind my DataSet to -->
<asp:Button ID="bRestricted" runat="server" OnClick="bRest_Click1" Text="Button" />
</Content>
</atlasToolkit:AccordionPane>

< /atlasToolkit:Accordion>

C# code

protected void Page_Load(object sender, EventArgs e)
{
String invoice = Session["invoice"].ToString();
DataSet data = ws.fillMain(invoice); //webservice to returns a DataSet
GridView gvRest = (GridView)AccordionRest.ContentContainer.FindControl("gvRest"); //This how I would get GridView, but I doesn't work to add Data to a GridView
gvRest.DataSource = data.Tables[0];
gvRest.DataBind();
}

If anyone has run into this problem and has figured out how to do this please let me know, thank you

I would create and bind the gridview in codebehind...

<atlasToolkit:AccordionID="MyAccordion"runat="server"SelectedIndex="0"

HeaderCssClass="accordionHeader"ContentCssClass="accordionContent"

FadeTransitions="true"FramesPerSecond="40"TransitionDuration="250"AutoSize="None">

</atlasToolkit:Accordion>

code behind:

...

AccordianPane pane =newAccordionPane();

pane.HeaderContainer.Controls.Add(newLiteralControl("headerName"));

pane.ContentContainer.Controls.Add(GetGridView());

MyAccordion.Controls.Add(pane);

privateGridView GetGridView(){

GridView gridView =newGridView();

...

}


Thanks for the help that worked Perfect.

I was able to add and populate the GridView control on the Accordion Pane. But I ran into an new obsticle. I have added a CommandField column to my GridView, and I want to catch the event when my commandview is selected. But I don't know how to declare the OnSelectedIndexChange in the code behind, and i dont' know if I catching the event correctly. Any help would be greatly appreciated, I am fairly new to ASP and Atlas, so detailed explainations and code examples are greatley appreicated.

Here is my code.

protected void Page_Load(object sender, EventArgs e) {try { String invoice = Session["invoice"].ToString(); DataSet data = ws.fillCustomer(invoice); GridView gvRestricted = NewGridView();/*how do I add a Command Field Event so I can catch it*/ gvRestricted.DataSource = data.Tables[0]; gvRestricted.DataBind(); AccordionRest.ContentContainer.Controls.Add(gvRestricted); }catch { } }public GridView NewGridView() { CommandField delete =new CommandField(); delete.ShowDeleteButton =true; delete.DeleteText ="Clear"; GridView grid =new GridView(); grid.CssClass ="gridView"; grid.HeaderStyle.CssClass ="gridViewHeader"; grid.FooterStyle.CssClass ="gridViewFooter"; grid.AlternatingRowStyle.CssClass ="gridViewAlternate"; grid.PagerStyle.CssClass ="gridViewPager"; grid.RowStyle.CssClass ="gridViewRow"; grid.Columns.Add(delete);return grid; }void gvRest_DeleteIndexChanged(Object sender, EventArgs e) { GridView grid = (GridView)AccordionRest.ContentContainer.FindControl("gvRest"); GridViewRow row = grid.SelectedRow;/*This is where I need to hand the event of the command field being triggered*/ }

I found the solution

grid.SelectedIndexChanged += new EventHandler(grid_SelecetedIndexChanged);

void grid_SelectedIndexChanged(Object sender, EventsArgs e)
{

}


I created the grid in code behind and register the PAgeIndexChanging event, but when I click in a diferent Page number the event hadlr is not fired or is filtreded by the accordion control and I don't get to change the page. Besides the site does a Posta back, whichi is not correct, because the accordion is inside a UpdataPanel de Ajax.

I don't know how to solve this issue.

Thank in advance for you help.


Try doing this for each AccordionControl on your page in the Page_Load event (before doing anything else with the AccordionControls):

 
Accordion1.FindControl("dummy");

The "dummy" name isn't important, it's just that calling the FindControl method works around the problem. The full details of the problem were posted athttp://couldbedone.blogspot.com/2007/07/what-wrong-with-accordion-control.html (thanks to Yuriy!)

How do I create a WebService with mandatory elements in the request?

I need a bit of assitance creating a WebService. Say that I have something like this -

'The objectsPublic Class productPublic nameAs StringPublic priceAs DecimalEnd ClassPublic Class orderPublic customerAs StringPublic productsAs List(Of product)End Class'The DB layerPublic orderDBPublic Function commitOrder(orderAs order)As IntegerDim orderIdAs Integer'DB code ommittedReturn orderIdEnd FunctionEnd Class'The Web Service<System.Web.Services.WebService(Namespace:="http://localhost/")> _<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ToolboxItem(False)> _Public Class order_wsInherits System.Web.Services.WebService <WebMethod()> _Public Function commitOrder(ByVal orderAs order)As Integer Dim orderDBAs New orderDB()Return orderDB.commitOrder(order)End FunctionEnd Class
The WSDL I get contains something like -

<s:element name="commitOrder"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="order" type="tns:order" /></s:sequence></s:complexType></s:element><s:complexType name="order"><s:sequence><s:element minOccurs="0" maxOccurs="1" name="customer" type="s:string" /><s:element minOccurs="0" maxOccurs="1" name="products" type="tns:ArrayOfproducts" /></s:sequence></s:complexType><s:complexType name="ArrayOfproducts"><s:sequence><s:element minOccurs="0" maxOccurs="unbounded" name="product" nillable="true" type="tns:product" /></s:sequence></s:complexType><s:complexType name="product"><s:sequence><s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" /><s:element minOccurs="0" maxOccurs="1" name="price" type="s:decimal" /></s:sequence></s:complexType>

Notice that everything is minoccurs="0" and the product entry in the ArrayOfproducts is nillable. How do I make it so that specific bits are required (minoccurs="1" and/or product element not nillable)?

Thanks

Martin

You could set a web service header so they always send you those requiered fields.


I'm not sure that I understand what you mean. But, just to elaborate on what I am looking for, the WSDL should contain tags that specify minOccurs="1".


Might be better to use discrete parameters rather than sending an order object. Most people find that more straightforward to use.


How would you control mandatory / optional elements using discrete parameters?

In any case, I'm already severely restricted in my attempts to use best coding practices by the inadequacies of .Net's WebService implementation. If I can't even control mandatory elements in this scenario I'll give it a miss and look at using Java and Mule.

Wednesday, March 21, 2012

how can i make draggable/dockable elements on a web page

I want to create a web page where I can drag and drop content, and dock it on other parts of the page. I also want that content to remain in the most current position on the page when the page is reloaded. I want to do something along the lines of what they did atPageflakes but I have no clue how to implement it. Can anyone offer suggestions? I just need some pointers as how I should approach this.

Thanks!

I have discovered the wonderful world of webparts, which answers my question here. Check outthis article if you want to learn to create these kinds of sites too.