I have a radgrid and a javascript in an ASP page.
This is the script:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function ViewCheck(filename) {
var targetfile = "Allegati/"+ filename;
var openWnd = radopen(targetfile, "RadWindowDetails");
}
</script>
The above script is supposed to pass the path of a file to a Radwindow and is working fine.
My problem is that for various reasons, I now need now to create subfolders of "Allegati" to store the files separately for each record. Such subfolders are named with the recordID value.
So now the var "targetfile" should be:
var targetfile = "Allegati/"+ recordID + filename;
In code behind, I get the recordID as following:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string recordID = editedItem.GetDataKeyValue("TransazioneID").ToString();
}
}
How can I pass the subfolder value "recordID" to the javascript in the asp page to get the complete path of the folder containing the files?
Please try with the below code snippet. Let me know if any concern.
JS
<script type="text/javascript">
function OPenPopuP(id, name, serverPath) {
var targetfile = serverPath + "/Allegati/" + id + "/" + name;
var openWnd = radopen(targetfile, "RadWindowDetails");
return false;
}
</script>
ASPX
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID,FileName">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
ASPX.CS
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data1 = new[] {
new { ID = 1, Name ="Name_1",FileName = "jayesh-Softweb.jpg"},
new { ID = 2, Name = "Name_2",FileName = "jayesh-Softweb.jpg"},
new { ID = 3, Name = "Name_3",FileName = "jayesh-Softweb.jpg"},
new { ID = 4, Name = "Name_4",FileName = "jayesh-Softweb.jpg"},
new { ID = 5, Name = "Name_5",FileName = "jayesh-Softweb.jpg"}
};
RadGrid1.DataSource = data1;
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
string strID = item.GetDataKeyValue("ID").ToString();
string strFileName = item.GetDataKeyValue("FileName").ToString();
Button Button1 = item.FindControl("Button1") as Button;
Button1.Attributes.Add("onclick", "return OPenPopuP('" + strID + "','" + strFileName + "','" + Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "');");
}
else if (e.Item.IsInEditMode && e.Item is GridEditableItem)
{
GridEditableItem item = e.Item as GridEditableItem;
string strID = item.GetDataKeyValue("ID").ToString();
string strFileName = item.GetDataKeyValue("FileName").ToString();
Button Button1 = item.FindControl("Button1") as Button;
Button1.Attributes.Add("onclick", "return OPenPopuP('" + strID + "','" + strFileName + "','" + Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "');");
}
}
Add a hidden field to your aspx page.
<asp:HiddenField ID="hfrecordID" runat="server" />
And assign the recodId to it in the ItemDataBound event and use it in the aspx page.
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function ViewCheck(filename) {
var targetfile = "Allegati/" + <%= hfrecordID.value %> + filename;
var openWnd = radopen(targetfile, "RadWindowDetails");
}
</script>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
hfrecordID= editedItem.GetDataKeyValue("TransazioneID").ToString();
}
}
Related
aspx:
<asp:FileUpload runat="server" ID="PicUpload" CssClass="btn btn-sm xor"/>
aspx.cs:
PicUpload.SaveAs(Path.Combine("C:\\Users\\KeepKids\\KeepKids\\pics\\", PicUpload.FileName));
why PicUpload.FileName ="" ?
In one place I do the same action and I get the picture. and here I get ""
I am find from below link:
https://www.aspforums.net/Threads/136183/ASPNet-FileUpload-control-Issue-FileName-is-blank-always-blank/
Can you please try this:
**PicUpload.PostedFile.FileName**
Something like below:
protected void btnsubmit_Click(object sender, EventArgs e)
{
string filename = "";
if (uploadphoto.PostedFile != null)
{
filename = Path.GetFileName(uploadphoto.PostedFile.FileName);
if (filename != "")
{
uploadphoto.SaveAs(Server.MapPath("images/" + filename));
string path = "images/" + filename;
}
}
}
<asp:FileUpload ID="FileUploadControl" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload File"
onclick="UploadButton_Click" />
<br />
<asp:Label ID="lblMessage" Font-Bold="true" runat="server">
</asp:Label>
Below is the click event which picks up the filename from FileUploadControl
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
lblMessage.Text = "Upload status: File uploaded!";
}
catch(Exception ex)
{
lblMessage.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
I need to create dynamic form, which i will have to create the textbox, textarea,dropdown etc, based on the field type.
Now, I have successfully created this dynamic textbox etc using my rowdatabound.
My problem is I could not retrieve the textbox value entered when the save button is clicked.
My aspx file
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="selectProspect" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FieldTitle" HeaderText="" />
<asp:BoundField DataField="FieldType" HeaderText="FieldType" />
<asp:TemplateField>
<ItemTemplate>
//DYNAMICALLY ADDING TEXTBOX
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RightText" HeaderText="" />
<asp:BoundField DataField="TemplatesInfoCode" HeaderText="TemplatesInfoCode" ItemStyle-CssClass="hiddencol" />
</Columns>
</asp:GridView>
My code behind file
protected void Page_Load(object sender, EventArgs e)
{
GetTemplateComponent();
}
public void GetTemplateComponent()
{
StringBuilder sb;
DataSet ds;
sb = new StringBuilder();
sb.AppendLine("select * from template where tc='0002' order by Sequence");
ds = Conn.DataAdapter(CommandType.Text, sb.ToString());
gv.DataSource = ds;
gv.DataBind();
}
protected void gv_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string value = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "FieldType"));
if (value == "Date" || value == "TextBox")
{
TextBox TextBox1 = new TextBox() { ID = "TextBox1", EnableViewState = false, CssClass = "form-control" };
e.Row.Cells[3].Controls.Add(TextBox1);
}
if (value == "TextArea")
{
TextBox DateTextBox = new TextBox() { EnableViewState = false, CssClass = "form-control", TextMode = TextBoxMode.MultiLine, Rows = 5, Columns = 50 };
e.Row.Cells[3].Controls.Add(DateTextBox);
}
if (value == "Content")
{
TextBox ContentAreaControl = new TextBox()
{
TextMode = TextBoxMode.MultiLine,
EnableViewState = false,
Columns = 10,
MaxLength = 150,
Height = 200,
CssClass = "Content-container",
};
e.Row.Cells[3].Controls.Add(ContentAreaControl);
}
}
}
protected void SaveTemplateDetails(object sender, EventArgs e)
{
foreach (GridViewRow row in gv.Rows)
{
FieldValue.Value = row.Cells[3].Text.ToString();
*//I DONT KNOW HOW TO READ THE VALUE*
}
}
I just want to know how is the proper way to read this dynamically created textbox
Thank you
ASPX Page Code.
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="gv_RowDataBound1">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="selectProspect" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FieldTitle" HeaderText="" />
<asp:BoundField DataField="FieldType" HeaderText="FieldType" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RightText" HeaderText="" />
<asp:BoundField DataField="TemplatesInfoCode" HeaderText="TemplatesInfoCode" />
</Columns>
</asp:GridView>
Code behind file
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string fieldType = e.Row.Cells[2].Text;
TextBox txtData = e.Row.Cells[3].FindControl("TextBox1") as TextBox;
switch (fieldType)
{
case "Date":
case "TextBox":
txtData.EnableViewState = false;
txtData.CssClass = "form-control";
break;
case "TextArea":
txtData.EnableViewState = false;
txtData.CssClass = "form-control";
txtData.TextMode = TextBoxMode.MultiLine;
txtData.Rows = 5;
txtData.Columns = 50;
break;
case "Content":
txtData.TextMode = TextBoxMode.MultiLine;
txtData.EnableViewState = false;
txtData.Columns = 10;
txtData.MaxLength = 150;
txtData.Height = 200;
txtData.CssClass = "Content-container";
break;
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
SaveTemplateDetails();
}
private void SaveTemplateDetails()
{
foreach (GridViewRow row in gv.Rows)
{
foreach (Control c in row.Cells[3].Controls)
{
TextBox txtDate = c as TextBox;
if (txtDate != null)
{
string data = txtDate.Text;
}
}
}
}
I can't to display file icons according to file extensions in asp.net GridView.
The structure of GridView is nested
The tutorial is Displays file icons in asp.net
The error is :
Object reference not set to an instance of an object
In this line of code-behind :
if (!String.IsNullOrEmpty(lnkDownload.Text))
My code below.
Can you help me?
Thank you in advance for any help, really appreciated.
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server"
AutoGenerateColumns="false" CssClass="mGrid" Width="700"
HorizontalAlign="Center">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img id="fileImage" runat="server" src="" />
<asp:HiddenField ID="HiddenField1"
runat="server" Value='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download" ItemStyle-
HorizontalAlign="Justify">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text='<%#
Eval("Name") %>' CommandArgument=
'<%# Eval("FullName") %>' runat="server"
OnClick="lnkDownload_Click"
OnClientClick="if (!confirm('Confirm ?'))
return false;"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string root = #FilePath;
string folder = GridView2.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvOrders = (GridView)e.Row.FindControl("gvOrders");
Label gvLabel = (Label)e.Row.FindControl("gvLabel");
Label gvFolder = (Label)e.Row.FindControl("gvFolder");
DirectoryInfo directory = new DirectoryInfo(root + "/" + folder);
FileInfo[] fileInfo = directory.GetFiles("*.*",
SearchOption.AllDirectories);
fCount = directory.GetFiles("*.*",
SearchOption.AllDirectories).Length;
gvLabel.Text = fCount.ToString();
long size = 0;
foreach (string file in Directory.GetFiles(root + "/" + folder,
"*.*", SearchOption.AllDirectories))
{
size += new FileInfo(file).Length;
}
gvFolder.Text = Math.Round((double)size / (double)(1024 * 1024),
2).ToString() + " MB";
LinkButton lnkDownload =
(LinkButton)e.Row.FindControl("lnkDownload");
HiddenField hf = (HiddenField)e.Row.FindControl("HiddenField1");
if (!String.IsNullOrEmpty(lnkDownload.Text))
{
HtmlImage image = (HtmlImage)e.Row.FindControl("fileImage");
image.Attributes.Add("src", GetIconForFile(hf.Value));
}
gvOrders.DataSource = fileInfo;
gvOrders.DataBind();
}
}
private string GetIconForFile(string fileText)
{
string extension = Path.GetExtension(fileText);
extension = extension.Trim('.').ToLower();
return "~/fileicons/" + extension + ".png";
}
You have a Nested GridView Structure and gvOrders is your inner GridView. So, you've to get LinkButton from inner GridView's row as like:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gvOrders = (GridView)e.Row.FindControl("gvOrders");
foreach (GridViewRow row in gvOrders.Rows)
{
LinkButton lnkDownload = (LinkButton)row.FindControl("lnkDownload");
HiddenField hf = (HiddenField)row.FindControl("HiddenField1");
if (!String.IsNullOrEmpty(lnkDownload.Text))
{
//... some code
}
}
}
}
I am working on resource files. I can now read resx file and get it populate the data into the grid-view. now here is my question now,
On a run time, i want to be able to edit the columns and also be able to click empty columns and click save to save my changes. How do i do that. please help me as i have tried many examples and it didn't work.
my code below,
private void btnNewfile_Click(object sender, EventArgs e)
{
for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
{
string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
string font = Between(comment, "[Font]", "[/Font]");
string datestamp = Between(comment, "[DateStamp]", "[/DateStamp]");
string commentVal = Between(comment, "[Comment]", "[/Comment]");
string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp, commentVal };
Gridview_Output.Rows.Add(row);
}
oDataSet.Tables.Add(oDataTable);
oDataSet.WriteXml(PathSelection);
}
Save button(the user must be able to save the file created or edit to any location (C drive))
private void btnSave_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = #"C:\";
saveFileDialog1.Title = "Save Resource Files";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.CheckPathExists = true;
saveFileDialog1.DefaultExt = "resx";
saveFileDialog1.Filter = "Save Resource Files (*.resx)|*.resx";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//nere i need the user to save to any location he want not textbox.
txtOutputfile.Text = saveFileDialog1.FileName;
}
//oDataSet.Tables.Add("Data");
oDataSet.WriteXml(PathSelection);
versionIncrement();
MessageBox.Show("Successfully added ");
}
See if the below code helps.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="UpdateResource.aspx.cs" Inherits="UpdateResource" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Update Resource</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
//Enable Disable all TextBoxes when Header Row CheckBox is checked.
$("[id*=chkHeader]").bind("click", function () {
var chkHeader = $(this);
//Find and reference the GridView.
var grid = $(this).closest("table");
//Loop through the CheckBoxes in each Row.
$("td", grid).find("input[type=checkbox]").each(function () {
//If Header CheckBox is checked.
//Then check all CheckBoxes and enable the TextBoxes.
if (chkHeader.is(":checked")) {
$(this).attr("checked", "checked");
var td = $("td", $(this).closest("tr"));
td.css({ "background-color": "#00000" });
$("input[type=text]", td).removeAttr("disabled");
} else {
$(this).removeAttr("checked");
var td = $("td", $(this).closest("tr"));
td.css({ "background-color": "#FFF" });
$("input[type=text]", td).attr("disabled", "disabled");
}
});
});
//Enable Disable TextBoxes in a Row when the Row CheckBox is checked.
$("[id*=chkRow]").bind("click", function () {
//Find and reference the GridView.
var grid = $(this).closest("table");
//Find and reference the Header CheckBox.
var chkHeader = $("[id*=chkHeader]", grid);
//If the CheckBox is Checked then enable the TextBoxes in thr Row.
if (!$(this).is(":checked")) {
var td = $("td", $(this).closest("tr"));
td.css({ "background-color": "#FFF" });
$("input[type=text]", td).attr("disabled", "disabled");
} else {
var td = $("td", $(this).closest("tr"));
td.css({ "background-color": "#00000" });
$("input[type=text]", td).removeAttr("disabled");
}
//Enable Header Row CheckBox if all the Row CheckBoxes are checked and vice versa.
if ($("[id*=chkRow]", grid).length == $("[id*=chkRow]:checked", grid).length) {
chkHeader.attr("checked", "checked");
} else {
chkHeader.removeAttr("checked");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="cmbResources" runat="server" AutoPostBack="true" OnSelectedIndexChanged="cmbResources_SelectedIndexChanged"
Width="275px">
</asp:DropDownList>
<br />
<br />
<asp:DataGrid ID="gridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
BorderColor="Black" BorderStyle="Groove" ForeColor="#333333" Width="500px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%= ++indexNum %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="English Word">
<ItemTemplate>
<%# DataBinder.Eval(Container,"DataItem.Key") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Translated Word">
<ItemTemplate>
<%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Value") %>'
BorderStyle="Groove" disabled="disabled"></asp:TextBox>--%>
<asp:TextBox ID="txtTrans" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Value") %>'
Enabled="false" BorderStyle="Groove"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<%--<asp:TemplateColumn>
<ItemTemplate>
<a href='editresource.aspx?key=<%# DataBinder.Eval(Container,"DataItem.Key") %>&file=<%=cmbResources.SelectedItem.Text %>&id=<%=indexNum - 1 %>'>
Edit</a>
</ItemTemplate>
</asp:TemplateColumn>--%>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<FooterStyle Font-Bold="True" ForeColor="White" />
<SelectedItemStyle Font-Bold="True" ForeColor="Navy" />
<PagerStyle ForeColor="#333333" HorizontalAlign="Center" />
<ItemStyle ForeColor="#333333" Font-Size="Small" Font-Names="verdana" />
<HeaderStyle Font-Bold="True" />
</asp:DataGrid>
<br />
<asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Resources;
using System.IO;
using System.Xml;
public partial class UpdateResource : System.Web.UI.Page
{
public int indexNum = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//string resourcespath = Request.PhysicalApplicationPath + "App_GlobalResources";
//DirectoryInfo dirInfo = new DirectoryInfo(resourcespath);
//foreach (FileInfo filInfo in dirInfo.GetFiles())
//{
// string filename = filInfo.Name;
// cmbResources.Items.Add(filename);
//}
//cmbResources.Items.Insert(0, new ListItem("Select a Resource File"));
string[] filePaths = Directory.GetFiles(#"C:\Users\D1956\Desktop\ResourceEdit", "*.aspx");
foreach (string file in filePaths)
{
string[] f = file.Split(new char[] { '\\' });
cmbResources.Items.Add(f[f.Length - 1]);
}
}
}
protected void cmbResources_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbResources.SelectedIndex != 0)
{
string filename = Request.PhysicalApplicationPath + "App_GlobalResources\\" + cmbResources.SelectedItem.Text;
Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
ResXResourceReader RrX = new ResXResourceReader(stream);
IDictionaryEnumerator RrEn = RrX.GetEnumerator();
SortedList slist = new SortedList();
while (RrEn.MoveNext())
{
slist.Add(RrEn.Key, RrEn.Value);
}
RrX.Close();
stream.Dispose();
gridView1.DataSource = slist;
gridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string filename = Request.PhysicalApplicationPath + "App_GlobalResources\\" + cmbResources.SelectedItem.Text;
string filename1 = filename.Remove(filename.Length - 5);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filename);
XmlNodeList nlist = xmlDoc.GetElementsByTagName("data");
for (int i = 0; i < gridView1.Items.Count; i++)
{
CheckBox chkItem = (CheckBox)gridView1.Items[i].FindControl("chkRow");
if (chkItem.Checked)
{
XmlNode childnode = nlist.Item(i);
XmlNode lastnode = childnode.SelectSingleNode("value");
TextBox txtTran = (TextBox)gridView1.Items[i].FindControl("txtTrans");
lastnode.InnerText = txtTran.Text.ToString();
}
}
xmlDoc.Save(filename1 + "_1" + ".resx");
}
}
You may have to edit the !IsPostback part.
i have a telerik grid and use GridTemplateColumn as bellow
<telerik:GridTemplateColumn DataField="Status" ReadOnly="true" UniqueName="colStatus" HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drpstatus" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
then i fill dropdown and label in ItemDataBound event :
protected void grdList_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
var info = (ProductViewInfo)e.Item.DataItem;
DropDownList drpstatus = (DropDownList)editItem["colStatus"].FindControl("drpstatus");
var cntType = new ProductTypeController();
var lst = cntType.GetStatusList(PortalId, enumTypes.MainGroup);
drpstatus.DataSource = lst;
drpstatus.DataTextField = "Caption";
drpstatus.DataValueField = "StatusID";
drpstatus.DataBind();
drpstatus.SelectedValue = info.Status.ToString();
}
else
{
var item = e.Item as GridDataItem;
var info = (ProductViewInfo)item.DataItem;
Label lblStatus = (Label)item["colStatus"].FindControl("lblStatus");
lblStatus.Text = info.StatusCaption;
}
}
}
but my drop down does not fill! "e.Item.IsInEditMode" always returns false. should i add anything else in order to fill dropdown?
I guess the problem related to ReadOnly="true"
try to remove it