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.
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:
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";
}
}
}
YCS
Please try the answer for the post and finally Don't forget to click “Mark as Answer” on the post that helped you.
hozefa_unwal...
Member
60 Points
92 Posts
Retrieve data in check box and update
Jan 08, 2013 07:04 PM|LINK
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.
chandrasheka...
Star
10258 Points
1760 Posts
Re: Retrieve data in check box and update
Jan 09, 2013 05:57 AM|LINK
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"; } } }Please try the answer for the post and finally Don't forget to click “Mark as Answer” on the post that helped you.
hozefa_unwal...
Member
60 Points
92 Posts
Re: Retrieve data in check box and update
Jan 09, 2013 09:15 PM|LINK
Will you be able to create a small project for me because I am getting string to boolean conversion error on status column.
Thanks.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Retrieve data in check box and update
Jan 10, 2013 01:35 AM|LINK
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"
hozefa_unwal...
Member
60 Points
92 Posts
Re: Retrieve data in check box and update
Jan 10, 2013 10:14 PM|LINK
I didn't have data dat's why i got error. thnx for your help.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Retrieve data in check box and update
Jan 11, 2013 03:43 AM|LINK
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?