protected void gvShowRList_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
hfBFResID.Value = "";
Label lblid = new Label();
if (e.CommandName == "Updates")
{
lblid = (Label)gvShowRList.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("lblIDs");
hfBFResID.Value = lblid.Text;
Windows win = new Windows();
win.IDS = int.Parse(hfBFResID.Value);
DataSet ds = new DataSet();
ds = win.GetDateSetForUpdate();
if (ds != null)
{
if (ds.Tables.Count>0)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlSite.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Site"]);
txtPage.Text = Convert.ToString(ds.Tables[0].Rows[0]["Page"]);
txtName.Text = Convert.ToString(ds.Tables[0].Rows[0]["Name"]);
chkActive.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsActive"]) == true ? true : false;
btnUpdate.Visible = true;
btnSave.Visible = false;
}
}
}
//lblmessage.Text = "";
//lblmessage.Visible = false;
}
}
catch (Exception ex)
{
AlertBoxes.ShowAlertMessage(ex.Message.ToString());
}
//finally
//{
// win = null;
// ds = null;
//}
}
=======================================================================
< asp:Panel ID="PnlRList" runat="server" CssClass="NullMargin">
< div class="marAuto">
< asp:Label ID="lblNoRecordFound" runat="server" Visible="false">< /asp:Label>
< asp:GridView ID="gvShowRList" runat="server" PageSize="15" AllowPaging="True" AutoGenerateColumns="False"
Width="100%" OnPageIndexChanging="gvShowRList_PageIndexChanging" GridLines="None"
OnRowCommand="gvShowRList_RowCommand" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last"
PagerSettings-Mode="NumericFirstLast" PagerSettings-Position="Bottom" PagerStyle-HorizontalAlign="Center"
CellSpacing="10" CellPadding="0">
< PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" />
< Columns>
< asp:TemplateField Visible="false">
< ItemTemplate>
< asp:Label ID="lblIDs" runat="server" Text='< %# Eval("ID") %>'>< /asp:Label>
< /ItemTemplate>
< /asp:TemplateField>
< asp:BoundField DataField="Name" HeaderStyle-HorizontalAlign="Left" HeaderText="Name"
ItemStyle-CssClass="brown_normal_txt" ItemStyle-Width="60%">
< HeaderStyle HorizontalAlign="Left" />
< ItemStyle CssClass="brown_normal_txt" Width="60%" />
< /asp:BoundField>
< asp:BoundField DataField="Page" HeaderStyle-HorizontalAlign="Left" HeaderText="Page"
ItemStyle-CssClass="brown_normal_txt" ItemStyle-Width="20%">
< HeaderStyle HorizontalAlign="Left" />
< ItemStyle CssClass="brown_normal_txt" Width="20%" />
< /asp:BoundField>
< asp:CheckBoxField DataField="IsActive" HeaderText="IsActive" HeaderStyle-HorizontalAlign="Left"
ItemStyle-CssClass="brown_normal_txt" ItemStyle-Width="20%">
< HeaderStyle HorizontalAlign="Left" />
< ItemStyle CssClass="brown_normal_txt" Width="20%" />
< /asp:CheckBoxField>
< asp:ButtonField ButtonType="Image" CommandName="Updates" HeaderText="Edit" ImageUrl="~/Images/edit.gif"
ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%">
< ItemStyle HorizontalAlign="Center" Width="10%" />
< /asp:ButtonField>
< /Columns>
< PagerStyle HorizontalAlign="Center" />
< /asp:GridView>
< /div>
< div class="clear">
< /div>
< /asp:Panel>
================================================================================
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Reflection;
using System.IO;
using System.Collections;
namespace System.Window
{
public class Resource
{
#region user defined function
public void LoadData(GridView gvResourceEditor,DropDownList ddlFileName, UpdatePanel UpdgvResourceEditor)
{
try
{
string strpath1 = HttpContext.Current.Server.MapPath("Resourcefile" + "\\" + Convert.ToString(ddlFileName.SelectedValue));
XElement resourceElements = XElement.Load(strpath1);
var _datasorce = (from resElem in resourceElements.Elements("data")
select new
{
Key = resElem.Attribute("name").Value,
Value = HttpUtility.HtmlEncode(resElem.Element("value").Value),
Comment = resElem.Element("comment") != null ?
HttpUtility.HtmlEncode(resElem.Element("comment").Value) : string.Empty
});
gvResourceEditor.DataSource = _datasorce;
gvResourceEditor.DataBind();
UpdgvResourceEditor.Update();
}
catch (Exception ex)
{
throw (ex);
}
}
#endregion
#region System Defined Function
public void gvResourceEditor_RowUpdating(GridView gvResourceEditor, GridViewUpdateEventArgs e,
DropDownList ddlFileName, UpdatePanel UpdgvResourceEditor)
{
try
{
string _strPath = HttpContext.Current.Server.MapPath("Resourcefile/" + Convert.ToString(ddlFileName.SelectedValue));
XDocument xDoc = XDocument.Load(_strPath);
Label lblKey = gvResourceEditor.Rows[e.RowIndex].FindControl("lblKey") as Label;
TextBox txtValue = gvResourceEditor.Rows[e.RowIndex].FindControl("txtValue") as TextBox;
string str1 = txtValue.Text;
//string str = txtValue.Text.Replace("\\r\\n", "
");
Hashtable ht = new Hashtable();
ht.Add("str", txtValue.Text.Replace("\\r\\n", "
"));
//str = txtValue.Text.Replace("
", System.Environment.NewLine);
var elementToBeEdited = from xle in xDoc.Element("root").Elements("data") where xle.Attribute("name").Value == lblKey.Text select xle;
if (elementToBeEdited != null && elementToBeEdited.Count() > 0)
{
//Updating the new value
elementToBeEdited.First().SetElementValue("value", HttpUtility.HtmlDecode(Convert.ToString(ht["str"])));
xDoc.Save(_strPath);
}
gvResourceEditor.EditIndex = -1;
LoadData(gvResourceEditor,ddlFileName,UpdgvResourceEditor);
//}
}
catch (Exception ex)
{
AlertBoxes.ShowAlertMessage(ex.Message.ToString());
}
}
public void gvResourceEditor_RowEditing(GridView gvResourceEditor, GridViewEditEventArgs e,
DropDownList ddlFileName, UpdatePanel UpdgvResourceEditor)
{
try
{
gvResourceEditor.EditIndex = e.NewEditIndex;
LoadData(gvResourceEditor, ddlFileName, UpdgvResourceEditor);
}
catch (Exception ex)
{
AlertBoxes.ShowAlertMessage(ex.Message.ToString());
}
}
public void gvResourceEditor_RowCancelingEdit(GridView gvResourceEditor, GridViewCancelEditEventArgs e,
DropDownList ddlFileName, UpdatePanel UpdgvResourceEditor)
{
try
{
gvResourceEditor.EditIndex = -1;
LoadData(gvResourceEditor, ddlFileName, UpdgvResourceEditor);
}
catch (Exception ex)
{
AlertBoxes.ShowAlertMessage(ex.Message.ToString());
}
}
public void ddlFileName_SelectedIndexChanged(GridView gvResourceEditor,
DropDownList ddlFileName, UpdatePanel UpdgvResourceEditor)
{
try
{
if (Convert.ToString(ddlFileName.SelectedValue) != "Resource File Name")
{
LoadData(gvResourceEditor, ddlFileName, UpdgvResourceEditor);
}
else
{
gvResourceEditor.DataSource = null;
gvResourceEditor.DataBind();
UpdgvResourceEditor.Update();
}
}
catch (Exception ex)
{
AlertBoxes.ShowAlertMessage(ex.Message.ToString());
}
}
#endregion
}
}
0 comments:
Post a Comment