locked
Retrieve data in check box and update RRS feed

  • Question

  • User-2131816816 posted

    Hi,

    I have one very small xml file. I want to retrieve data and also update my xml file. I have only 2 fields and out of that only one is editable which is "Status". I have one gridview with two columns and Want to put check box as Status column. I have one button outside gridview. on a pageload i can see all my data and whatever i will change in my checkbox and click on Save button then it will update my xml file and display with new effect of my data.

    Below is my xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <StoredProcedure>
    <Parameter menuitems="One">
    <Status></Status>
    </Parameter>
    <Parameter menuitems="Two">
    <Status></Status>
    </Parameter>
    <Parameter menuitems="Threee">
    <Status></Status>
    </Parameter>
    </StoredProcedure>

    Grid view.

    <asp:GridView ID="grdItems" runat="server" AutoGenerateColumns="False" CellPadding="4"
    EnableModelValidation="True" Font-Names="Verdana" Font-Size="Small" ForeColor="#333333"
    Width="100%">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
    <asp:BoundField DataField="menuitems" HeaderText="Menu Items Description" ItemStyle-Width="100%"
    ReadOnly="true" />
    <asp:TemplateField HeaderText="Status" ItemStyle-Width="100%">
    <ItemTemplate>
    <asp:CheckBox ID="chkstatus" runat="server" Checked='<%#Convert.ToBoolean(Eval("Status")) %>' />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>

    I will really appreciate if someone can help me out.

    Thanks.

    Tuesday, January 8, 2013 3:04 PM

Answers

  • User3866881 posted

    because I am getting string to boolean  conversion error on status column.

    Hi,

    Please try this:

    bool b = Convert.ToBoolean("true“);

    Or just use a logic expression with string:

    bool b = Some logic expression with string, something like "a"=="b"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 9, 2013 9:35 PM

All replies

  • User-1516073966 posted

    Hi

    Instead of binding the "menuitems" value to a "boundfield" bind that to a label in template field which helps you in updating the "status" value in the xml(i.e tracking the exact menu item and updating the status for that).

    i.e. Then your markup should look like as follows:

    <asp:TemplateField HeaderText="Status" ItemStyle-Width="100%">
    <ItemTemplate>
    <asp:Label id="lblMenuItems" runat="server" Text='<%#Eval("menuitems") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    With the above changes you can retrieve the label value(i.e lblMenuItems) in code behind and track the status in the xml and update and then save the xml.
    which would be like as follows:

    //here load the xml file into the xml document.
    XmlDocument doc = new XmlDocument();
    doc.Load(xmlFilePath);
    
    forech(GridViewRow row in grdItems.Rows)
    {
    //here find the label which you have replaced bound field with the template field.
    Label lblItems = row.FindControl("lblMenuItems") as Label;
    CheckBox statusBox = row.Findcontrol("chkstatus") as CheckBox;
    
    if(lblItems != null)
    {
    //here write xpath to retrieve the status node based on the selected menu item.
    XmlNode statusNode = doc.SelectSingleNode(string.Format("/StoredProcedure/Parameter[@menuitems='{0}']/Status", lblItems.Text));
    if(statuNode != null && statusBox != null)
    {
    statusNode.InnerText = (statusBox.Checked) ? "True" : "False"; 
    } 
    }
    
    }

    Wednesday, January 9, 2013 1:57 AM
  • User-2131816816 posted

    Will you be able to create a small project for me because I am getting string to boolean  conversion error on status column.

    Thanks.

    Wednesday, January 9, 2013 5:15 PM
  • User3866881 posted

    because I am getting string to boolean  conversion error on status column.

    Hi,

    Please try this:

    bool b = Convert.ToBoolean("true“);

    Or just use a logic expression with string:

    bool b = Some logic expression with string, something like "a"=="b"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 9, 2013 9:35 PM
  • User-2131816816 posted

    I didn't have data dat's why i got error. thnx for your help.

    Thursday, January 10, 2013 6:14 PM
  • User3866881 posted

    I didn't have data dat's why i got error. thnx for your help.

    Hi again,

    I find that there's something wrong with your problem. And then here's my idea.

    And I find that you've solved your problem because the issue's state is Green.

    Is your problem solved totally?

    Thursday, January 10, 2013 11:43 PM