I was infact wrong, that does not work unfortunately.

Any ideas?

I have now sorted this issue out.

Code below:

[code]
void binddata()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn dc in ds.Tables[0].Columns)
{
dc.ColumnMapping = MappingType.Attribute;
}

    //Dataview customised so that it can sort by, 'SortOrder' column.
    System.Data.DataView dv = new System.Data.DataView(ds.Tables[0]);
    // dv.Sort = string.Format("SortOrder ASC");
    dv.Sort = GridViewSortExpression;

}

private string GridViewSortExpression
{
    get { return ViewState["SortOrder"] as string ?? string.Empty; }

    set { ViewState["SortOrder"] = value; }
}

[/code]

Hello

I'm currently using GridView.Sort("Column", ASC")

It works perfectly and sorts my gridview, however once I get to 10 or higher the sort order stops working and it goes. 1,10,2,3,4,5,6,7,9.

Here is my code would anyone care to explain why it does this?

[CODE] DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn dc in ds.Tables[0].Columns)
{
dc.ColumnMapping = MappingType.Attribute;
}

    //Dataview customised so that it can sort by, 'SortOrder' column.
     System.Data.DataView dv = new System.Data.DataView(ds.Tables[0]);
     dv.Sort = "SortOrder ASC";

    gv.DataSource = dv;
    gv.DataBind();[/CODE]

SortOrder is just a number from 1-100.

Thank you!

How would you do that in c# ?

Thanks

Hello

I'm trying to include a dropdownlist in my gridview and then bind data to that dropdownlist.

I have come across an error:

[quote]
error CS0103: The name 'sortOrderDropDown2' does not exist in the current context at System.Web.Compilation.AssemblyBuilder.Compile()
[/quote]

Now i'm not sure why I get this error as my asp file clearly has a dropdown with the ID="sortOrderDropDown2"

[code]

[/code]

Now here is my PageLoad code in my c# file:

[code]
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

    //Get first/last sortOrder from XML file and display
    ArrayList sortOrderArrayMax = sortOrderListMax();
    int maxSortOrder = sortOrderArrayMax.Count - 1;

    string sortOrderMax = sortOrderArrayMax[maxSortOrder].ToString();

    sortOrderHigh.Text = sortOrderMax;

    //My dropdown list using the datasource from the above arraylist - gets max value.

    sortOrderDropDown2.DataSource = sortOrderArrayMax;
    sortOrderDropDown2.DataBind();

    ArrayList sortOrderArrayMin = sortOrderListMin();
    int minSortOrder = sortOrderArrayMin.Count - 1;

    string sortOrderMin = sortOrderArrayMin[minSortOrder].ToString();

    sortOrderLow.Text = sortOrderMin;

binddata();

}

}

[/code]

Is there any reason I get this error as it clearly is there?

Thank you

Hello

I'm currently trying to get my GridView to update all rows at the same time.

The gridview takes data from an .XML file - I can use the 'onRowEditing' to update a single row at a time - however I want it to be able to update all rows at the same time.

What is the best approach for this - I currently use a 'showEditButton' button but as said this only updates a single row.

What would be the easiest way to update all rows - can I use a textbox in the gridview rather than a label and just have an 'Update' button.

Here is my current 'Updatedata' which is linked to the edit button.

[code]
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn dc in ds.Tables[0].Columns)
{
dc.ColumnMapping = MappingType.Attribute;
}
int i = e.RowIndex;
string sDataField = (gv.Rows[e.RowIndex].FindControl("txtDataField") as TextBox).Text;
string sHeader = (gv.Rows[e.RowIndex].FindControl("txtHeader") as TextBox).Text;
string sUseDefaults = (gv.Rows[e.RowIndex].FindControl("txtUseDefaults") as TextBox).Text;
string sSortOrder = (gv.Rows[e.RowIndex].FindControl("txtSortOrder") as TextBox).Text;
gv.EditIndex = -1;
binddata();
DataView dv = new DataView(ds.Tables[0]);
gv.DataSource = dv;
//Lets add some random data into the first column to prove that I can auto create the Axx ID up to A99
ds.Tables[0].Rows[i]["DataField"] = sDataField;
ds.Tables[0].Rows[i]["Header"] = sHeader;
ds.Tables[0].Rows[i]["UseDefaults"] = sUseDefaults;
ds.Tables[0].Rows[i]["SortOrder"] = sSortOrder;
ds.WriteXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
binddata();
Page.Response.Redirect(Page.Request.Url.ToString(), true);
[/code]

Hello

I'm trying to take Data from my GridView at the moment.

My gridview has a column called 'DataField' what I want to do is take those values from Datafield to calculate the highest value.

The 'Datafield' are as follows: A10, A11, A12 etc.

How can I take those values (A10, A11, A12) and place them into a textbox, or calculate the highest value and put that into a textbox.

My c# code for the DataBind is below:

[code]
void binddata()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn dc in ds.Tables[0].Columns)
{
dc.ColumnMapping = MappingType.Attribute;
}

     DataView dv = new DataView(ds.Tables[0]);

     dv.Sort = "SortOrder ASC";

    gv.DataSource = dv;
    gv.DataBind();

[/code]

Many thanks!

Here is an example of code I use to read an XML file.

[code]
void binddata()
{
DataSet dsName = new DataSet();
dsName.ReadXml("C:/XMLFILEHERE"));
foreach (DataColumn da in dsName.Tables[0].Columns)
{
da.ColumnMapping = MappingType.Attribute;
}
}
[/code]

I've now sorted it using my DataBind as follows:

[code]
void binddata()
{
DataSet rdawTest = new DataSet();
rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn da in rdawTest.Tables[0].Columns)
{
da.ColumnMapping = MappingType.Attribute;
}

    System.Data.DataView dv = new System.Data.DataView(rdawTest.Tables[0]);
    dv.Sort = "SortOrder ASC";

        rd.DataSource = dv;
        rd.DataBind();
}

[/code]

Thanks for help.

I've tried @SortOrder but still no luck it's just blank when I open the XML document?

[Code]
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

[/Code]

Hello

I've tried another approach to my gridview sort, but i'm getting an error hope it's easy enough to resolve.

My code is below:

[code]
void binddata()
{
DataSet rdawTest = new DataSet();
rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn da in rdawTest.Tables[0].Columns)
{
da.ColumnMapping = MappingType.Attribute;
}

        rd.DataSource = rdawTest;
        rd.DataBind();

}

protected void gridview_Sort(object sender,GridViewSortEventArgs e)
{
    string sortExpression = e.SortExpression; 
    string direction = string.Empty;
    if (SortDirection == SortDirection.Ascending) 
    { 
       SortDirection = SortDirection.Descending; direction = " DESC";
    } 
    else 
    { 
        SortDirection = SortDirection.Ascending; direction = " ASC";
    }
    DataTable table = this.GetData();
    table.DefaultView.Sort = "SortOrder";
    rd.DataSource = table;
    rd.DataBind();
}

private DataTable GetData()
{
    DataTable table = new DataTable();
    DataSet rdawTest = new DataSet();
    rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
    foreach (DataColumn da in rdawTest.Tables[0].Columns)
    {
        da.ColumnMapping = MappingType.Attribute;
    }

    rd.DataSource = rdawTest;
    rd.DataBind();
    return table;
}

[/code]

However this is not working as when I click the header to sort it says the following:

[quote]
Cannot find column SortOrder. at System.Data.DataTable.ParseSortString(String sortString)
at System.Data.DataView.CheckSort(String sort)
at System.Data.DataView.set_Sort(String value)
[/quote]

I'd be grateful if someone could help me rectify this.
Thanks

Hello, i've tried it now but can't seem to get it working.

My XML code:
[code]
<?xml-stylesheet type="text/xsl" href="Y10_CCF_SPORT.xsl" version="1.0" standalone="yes"?>

[/code]

My XSL code:
[code]
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

[/code]

[QUOTE=pritaeas;1590456]If you use an xslt to transform it, then you can use xsl:sort. [URL="http://www.xml.com/pub/a/2002/07/03/transform.html"]This link[/URL] shows how.[/QUOTE]

Thank you i'll look into this.

Does it still work for my XML file as it's and then Items?

Just the XML file they are using as an example is slighlty different.

Thanks

My code uses an XML file where it collects the data.

I've tried the following code but I get an error:
[code]
protected void gridview_Sort(object s,GridViewSortEventArgs e)
{
DataSet rdawTest = new DataSet();
rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn da in rdawTest.Tables[0].Columns)
{
da.ColumnMapping = MappingType.Attribute;
}
DataView dv = rdawTest.Tables["table"].DefaultView;
dv.Sort = "sortOrder ASC";

    rd.DataSource = dv;
    rd.DataBind();
}

[/code]

The error:
[quote]Object reference not set to an instance of an object [/quote]

Hello

I have an XML file that uses

I was wondering if it is possible to sort my XML file by sortOrder?

Here is an example of my code:

[code]
<?xml version="1.0" standalone="yes"?>

[/code]

I just want SortOrder to be sorted ascending when you view the XML file.

Thanks

Hello, the above code now looks like this:

It is for a web application not a windows form - which I realise is in the wrong area.

[CODE] string[] columnData = new string[rd.Rows.Count];
for (int i = 0; i < rd.Rows.Count; i++)
{
GridViewRow row = rd.Rows[i] as GridViewRow;
columnData[i] = row.Cells["SortOrder"].Value.ToString();
}[/CODE]

The last line of code however gives me an error:

[Quote]
error CS1502: The best overloaded method match for 'System.Web.UI.WebControls.TableCellCollection.this[int]' has some invalid arguments
[/Quote]

Yes sorry I wanted to convert a Column of a datagridview into an array.

Hello

I currently have a Datagridview which takes data from an XML file.

I want to display the array of numbers.

Here is the code for my GridView:

<asp:GridView ID="rd" runat="Server" OnRowEditing="Editdata" OnPageIndexChanging="pageddata"
        OnRowDeleting="Deletedata" OnRowUpdating="Updatedata" OnRowCancelingEdit="Canceldata"
        AllowPaging="True" AutoGenerateColumns="False" PageSize="30" CellPadding="4"
        ForeColor="#333333" GridLines="None">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:TemplateField HeaderText="DataField">
                <ItemTemplate>
                    <asp:Label ID="lblDataField" runat="server" Text='<%#Eval("DataField") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtDataField" runat="server" ReadOnly="true" Visible="true" Text='<%#Eval("DataField") %>'></asp:TextBox>
                    <%-- Visible=false to hide textbox, ReadOnly=true to make textbox ReadOnly --%>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Header">
                <ItemTemplate>
                    <asp:Label ID="lblHeader" runat="server" Text='<%#Eval("Header") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtHeader" runat="server" Text='<%#Eval("Header") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="UseDefaults">
                <ItemTemplate>
                    <asp:Label ID="lblUseDefaults" runat="server" Text='<%#Eval("UseDefaults") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtUseDefaults" runat="server" Text='<%#Eval("UseDefaults") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" ButtonType="Button" />
            <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
        </Columns>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

Now what I want to do know is how can I obtain an array of the DataField column. For example it has A01, A02, A03 I need to check how many entries exist and them put them into a textbox for example.

Is this possible?

I've currently used this to take the last 'DataFeild' value from the gridview:

void binddata()
{
    DataSet rdawTest = new DataSet();
    rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
    foreach (DataColumn da in rdawTest.Tables[0].Columns)
    {
        da.ColumnMapping = MappingType.Attribute;
    }
    rd.DataSource = rdawTest;        
    rd.DataBind();

    DataSet ds = rd.DataSource as DataSet;
    DataRow dr = ds.Tables[0].NewRow();

    int index = rd.Rows.Count - 1;

    GridViewRow gRow = rd.Rows[index]; ...

Hello

I'm trying to sort my gridview by a particular colum.

My gridview has a column which is 'Sort Order' and they are numbered 1,2,3 etc.

Now I want to be able to default sort that column in ascending order.

Would anyone possibly be able to help?

Here is my ASP.net code:

[code]
<asp:GridView ID="rd" runat="Server" OnPageIndexChanging="pageddata"
AllowPaging="True" AutoGenerateColumns="False" PageSize="30" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowSorting="true" OnSorting="onSort">

        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:TemplateField HeaderText="DataField">
                <ItemTemplate>
                    <asp:Label ID="lblDataField" runat="server" Text='<%#Eval("DataField") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtDataField" runat="server" ReadOnly="true" Visible="true" Text='<%#Eval("DataField") %>'></asp:TextBox>
                    <%-- Visible=false to hide textbox, ReadOnly=true to make textbox ReadOnly --%>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Header">
                <ItemTemplate>
                    <asp:Label ID="lblHeader" runat="server" Text='<%#Eval("Header") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtHeader" runat="server" Text='<%#Eval("Header") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="UseDefaults">
                <ItemTemplate>
                    <asp:Label ID="lblUseDefaults" runat="server" Text='<%#Eval("UseDefaults") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtUseDefaults" runat="server" Text='<%#Eval("UseDefaults") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
           <%-- Taking Sort Order from XML file --%>
            <asp:TemplateField HeaderText="Sort Order" SortExpression="sortOrder">
            <ItemTemplate>
            <asp:Label ID="lblSortOrder" runat="server" Text='<%#Eval("SortOrder") %>'></asp:Label>
            </ItemTemplate>

            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" ButtonType="Button" />
            <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
        </Columns>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />

    </asp:GridView>

[/code]

The DataBind:

[CODE] void binddata()
{
DataSet rdawTest = new DataSet();
rdawTest.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
foreach (DataColumn da in rdawTest.Tables[0].Columns)
{
da.ColumnMapping = MappingType.Attribute;
}
rd.DataSource = rdawTest;

    rd.DataBind();
}

[/CODE]

Thank you in advance.

Is there any possible way to get it not to look in the virtual directory at all and point to a file locally?

Hey,

My database currently stores the location of a specific image, however i'm trying to get the page to change the

[CODE]img.ImageUrl = "C:\mug.jpg";[/code]

However it doesn't display the image, is there any reason for this?

If I use a local image it works perfectly IE:

[CODE]img.ImageUrl="~/images2/mug.jpg";[/CODE]

Any ideas at all please?

Hey,

i've read through that article but still having difficulty, it just writes the source of the image rather than the image itself?

Hi,

I've currently got a gridView which selects data from my table, it also has the URL of an image in one of the columns.

I want an imageField which can then display the image from the URL thats provided in the image column.

My datagrid:

[img]http://i41.tinypic.com/25ivst2.jpg[/img]

My code for the DataGrid:

[code]

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Height="234px" Width="459px" AllowPaging="True"
AllowSorting="True" onselectedindexchanged="GridView1_SelectedIndexChanged">

    </asp:GridView>

[/code]

As you can see the URL displays perfectly however I now want that URL image to be displayed in the GridView (icon column) as an actual Image.

Thank you.

I've now sorted this

[code]
lblCustomerID.Text = dataGridView1.CurrentRow.Cells["customerID"].FormattedValue.ToString();

        string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=coffee;Integrated Security=True;Pooling=False";
        conn = new SqlConnection(connectionString);
        sqlDelete = "DELETE FROM customer WHERE customerID = '" + lblCustomerID.Text + "'";
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = sqlDelete;
        cmd.Connection = conn;
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();

[/code]

Thanks for any help anyhow.

[QUOTE=yaninea;1164585]Add a column in your grid with a button or an image button as is set on my example:
[CODE]
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
ImageButton Button1 = (ImageButton)sender;
GridViewRow grdRow = (GridViewRow)Button1.Parent.Parent;
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = (DataView)this.SqlDataSource2.Select(args);
DataTable table = view.ToTable();
string id = table.Rows[grdRow.RowIndex].ItemArray[0].ToString();
}
[/CODE]
Hope it helps. let me know if you need a futher explanation. Good luck.[/QUOTE]

Hi i've added a button onto my datagridivew its on their as column.

I'm having trouble getting the above working however.

I've got a button (btnDelete) am I able to link that up, is there anyway I can simply get the coffeeID from the datagridview row that has been selected?

I have something like this:

[code]
DataTable dt = ds.Tables["coffeeType2"];
label1.Text = System.Convert.ToString(dt.Rows[0][2]);
[/code]

However that just selects the DataTable id second row - how can I do it dependent on what row the user has selected?

Can anyone be kind enough to help me with this?

Ok, do you have any idea how I would do this?

Ok thank you i'll have a look.

Is there anyway i'm able to get the ID of a select row at all?

Say my datagridview has ID, name, location.

When I click a cell can I get the ID of that particular row?

Hey,

I currently have a dataGridView which displays information from my SQL database. I have a button that I use to update/add into the SQL database - for example a user ammends a field in the dataGridView this automatically updates the database.

I now want to implement a button that deletes the selected row from the database.

My dataGridView loadData:

[code]
private void LoadData()
{
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=coffee;Integrated Security=True;Pooling=False";
conn = new SqlConnection(connectionString);
sql = "SELECT * FROM coffeeType2";

        da = new SqlDataAdapter(sql, conn);
        conn.Open();
        ds = new DataSet();
        SqlCommandBuilder commandBuilder = new SqlCommandBuilder(da);
        da.Fill(ds, "coffeeType2");
        bsource.DataSource = ds.Tables["coffeeType2"];
        dataGridView1.DataSource = bsource;

        // this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

        dataGridView1.AutoResizeColumns();
        dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
    }

[/code]

Add/Update Button:

[code]
private void btnAdd_Click(object sender, EventArgs e)
{
DataTable dt = ds.Tables["coffeeType2"];
this.dataGridView1.BindingContext[dt].EndCurrentEdit();
this.da.Update(dt);

        LoadData();
    }

[/code]

How can I now create a button to delete that particular row from the database?

Thank you.

Thanks for your help :)

Its highly appreciated.