个人收藏FAQ.

youngby 2003-05-17 01:16:52
这个贴子是诗人日记。


如何将xml转为txt而且去掉标记。
假设xml放在D;\user.xml

代码:
Dim ds As New DataSet()
'read from xml
ds.ReadXml("d:\user.xml")
'tranverse
Dim fs As New System.IO.FileStream("d:\11.txt", IO.FileMode.Create)
Dim sr As New System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"))
Dim i, j As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
sr.WriteLine(ds.Tables(0).Rows(i).Item(j))
Next
Next
sr.Close()
fs.Close()
...全文
61 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
youngby 2003-05-17
  • 打赏
  • 举报
回复
asp.net怎样调用treeview控件



到微软去下载安装文件:iewebcontrols.msi
youngby 2003-05-17
  • 打赏
  • 举报
回复
UP :PART TWO:


Now that we have the Web Form let's write the code to achieve what we are looking for.

Binding the DataGrid

We will write a helper function that actually binds our DataGrid with the DataSet. The following code shows this function:

private void BindGrid()
{
DataSet ds;
if(Session["data"]==null)
{
CreateDataSet();
}
ds=(DataSet)Session["data"];
DataGrid1.DataSource=ds;
DataGrid1.DataMember="orderdetails";
DataGrid1.DataBind();
}

The preceding code uses another helper function called CreateDataSet which we will discuss later. The above function firsts checks a session variable (data) for a null value. If we have not stored anything yet we create a new DataSet and store it in session (done inside the CreateDataSet function). We then bind our DataGrid with the DataSet.

CreateDataSet Function

The CreateDataSet function looks like this:

private void CreateDataSet()
{
DataSet ds=new DataSet();
SqlConnection cnn=new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
SqlDataAdapter da=new SqlDataAdapter("select * from orderdetails where 1=2",cnn);
da.Fill(ds,"orderdetails");
DataColumn colid=new DataColumn();
colid.ColumnName="id";
colid.AutoIncrement=true;
colid.AutoIncrementSeed=1;
ds.Tables[0].Columns.Add(colid);
}

The above code is typical data access code using the SqlClient namespace. Note the following two things:

In the SQL query we have specified a condition of 1=2. This is because we are not interested in the data, just the structure. If you want data back then you may modify the query to suit your requirements. You may add various columns manually as well.
We have added a new column called id that is auto incrementing. This column stores a unique id for the individual row. This column is used while deleting or accessing a row.
Page_Load Event

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindGrid();
txtOrderDate.Text=DateTime.Today.ToShortDateString();
txtReqdDate.Text=DateTime.Today.AddDays(30).ToShortDateString();
}
}

Inside the Page_Load event we simply call the BindGrid method. We also fill the TextBoxes with default values.

Adding Blank Rows to the DataGrid

This is the main part of the application. The Button.Click event looks like this:

private void btnAddProd_Click(object sender, System.EventArgs e)
{
DataSet ds=(DataSet)Session["data"];
DataRow row=ds.Tables[0].NewRow();
ds.Tables[0].Rows.Add(row);
BindGrid();
}

We have added a new row to the DataTable and bind the DataGrid again. Since our ItemTemplate itself consists of TextBoxes, the user gets a blank row ready for entering data.

Saving Entered Data

private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="save")
{
DataSet ds=(DataSet)Session["data"];
int rowid=int.Parse(e.Item.Cells[0].Text);
foreach(DataRow row in ds.Tables[0].Rows)
{
if((int)row["id"]==rowid)
{
row["productid"]=((TextBox)e.Item.Cells[1].Controls[1]).Text;
row["quantity"]=((TextBox)e.Item.Cells[2].Controls[1]).Text;
row.AcceptChanges();
ds.Tables[0].AcceptChanges();
break;
}
}
BindGrid();
}
}

Once the user enters any data into the blank row, he must save it back to the DataSet. This task is done in the "Save" LinkButton. Remember that we have set the CommandName property of this LinkButton to "save" so we must check for it here.

Deleting Rows

The user must be able to remove rows if he wishes. The DeleteCommand of the grid looks like this:

private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataSet ds=(DataSet)Session["data"];
int rowid=int.Parse(e.Item.Cells[0].Text);
foreach(DataRow row in ds.Tables[0].Rows)
{
if((int)row["id"]==rowid)
{
row.Delete();
break;
}
}
BindGrid();
}


来源:http://www.dotnetjunkies.com/printtutorial.aspx?tutorialid=319
youngby 2003-05-17
  • 打赏
  • 举报
回复
当Datagrid单元格获得焦点后,单元格右边会出现一个小按钮(可能是combobox),再点小按钮就会出现数据网格(可能是listview),点击数据网格的某一行,就把物料编码,物料名称,单位自动填到Datagrid的物料编码、物料名称上去.


Question:

I am building an application in ASP.net with SQL server as backend, which contains a Master/Detail relationship screen. The requirement is for inserting many rows of data against one row of master data. I would like to develop a screen where a user can make as many rows of entries as needed (for ex. for one Author, there can be many Titles and related details) in the detail area. If a db grid is used for this, I dont want to display any data in the grid as I am not interested in viewing anything and also I don't want to burden the form with lots of data.

Answer:

To solve this problem we are going to build an example Web Form that you can extend in your application. We will have two tables - OrderMaster and OrderDetails. As the names suggest the former is a master table where as the later is detail table. We want to add one record in the master table and several others in the detail table. We will not display any existing rows on the screen to maintain a clean page.

To follow this example you will need two tables in a SQL server database as follows:

Table Name Column Name Data Type
OrderMaster OrderID
OrderDate
RequiredDate
OrderingDepartment
AutoNumber
DateTime
DateTime
Char(20)

OrderDetails OrderID
ProductID
Quantity
Numberic
Char(20)
Numeric


The table structures are sufficient to illustrate our task; in reality you would have many other fields, like shipping details for example. The sample focuses on the problem of Master-detail record additions rather than database updates.

Following is the Web Form code for the above screen:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MultiEditDataGrid.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="80%" align="center" border="0">
<TR>
<TD>
<P align="right">
<asp:Label id="Label1" runat="server">Order Date :</asp:Label></P>
</TD>
<TD>
<asp:TextBox id="txtOrderDate" runat="server" ReadOnly="True"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<P align="right">
<asp:Label id="Label2" runat="server">Required Date :</asp:Label></P>
</TD>
<TD>
<asp:TextBox id="txtReqdDate" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<P align="right">
<asp:Label id="Label3" runat="server">Ordering Department :</asp:Label></P>
</TD>
<TD>
<asp:TextBox id="txtOrderingDept" runat="server">ACCOUNTS</asp:TextBox></TD>
</TR>
<TR>
<TD>
<P align="left">
<asp:Button id="btnAddProd" runat="server" BorderStyle="Solid" BackColor="#FFE0C0" Text="Add Product"></asp:Button></P>
</TD>
<TD>
<P align="right">
<asp:Button id="btnPlaceOrder" runat="server" BackColor="Navy" ForeColor="White" Font-Bold="True" Text="Place Order"></asp:Button></P>
</TD>
</TR>
<TR>
<TD colSpan="2">
<P align="center">
<asp:DataGrid id="DataGrid1" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" Width="100%" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="id" HeaderText="Row ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Product Code">
<ItemTemplate>
<asp:TextBox id="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductID") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Quantity Required">
<ItemTemplate>
<asp:TextBox id="TextBox4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Quantity") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Save" CommandName="save"></asp:ButtonColumn>
<asp:ButtonColumn Text="Remove" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid></P>
</TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
ENIGMATOO 2003-05-17
  • 打赏
  • 举报
回复
学习
youngby 2003-05-17
  • 打赏
  • 举报
回复
如何在浏览器中实现WORD的功能?我的目的:
在客户端打开服务器数据库中的word文件,编辑后再上传到数据库中.

把数据库上的文件下载到客户端的一个临时文件中,再用ie打开。但客户端必须装有Word才能打开。例:
Private Function 文件装载(ByVal LID As Integer) As String
Dim i, j, k As Integer
Dim b_file, c_file, s_file As String
Dim objDS As Byte()
Dim c_path As String = MapPath("kycrmtemp")
Dim LFile As IO.FileStream
For i = 0 To DataSet41.Tables("附件").Rows.Count - 1
With DataSet41.Tables("附件").Rows(i)
If .Item("ID") = LID Then
b_file = Trim(.Item("格式"))
Do
k = Int(Rnd() * 100000)
c_file = c_path & "\" & CStr(k) & "." & b_file
s_file = CStr(k) & "." & b_file
If Not IO.File.Exists(c_file) Then Exit Do
Loop
Try
objDS = .Item("文件")
LFile = New IO.FileStream(c_file, IO.FileMode.OpenOrCreate)
LFile.Write(objDS, 0, objDS.Length)
LFile.Close()
Catch
End Try
Exit For
End If
End With
Next
文件装载 = s_file
End Function上传部分:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As System.IO.Stream
Dim n, m As Integer
Dim cs() As Byte
Dim dd As New HtmlInputFile()
dd.ID = "dd"
TextBox1.Text = dd.PostedFile.ContentLength
n = dd.PostedFile.ContentLength
ReDim cs(n)
fs = dd.PostedFile.InputStream
fs.Read(cs, 0, n)
' dd.PostedFile.SaveAs("c:\ddd.nn")
SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@f", System.Data.SqlDbType.Image, n, ParameterDirection.Input, False, 0, 0, "f", DataRowVersion.Current, cs))
SqlCommand1.CommandText = "Insert into table1(f) values(@f)"
fs.Close()
SqlCn.Open()
SqlCommand1.ExecuteNonQuery()
SqlCn.Close()

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As System.IO.Stream '使用http的io.stream的方法上传文件
Dim n, m As Integer
Dim cs() As Byte '用来临时存储文件的数组
n = dd.PostedFile.ContentLength '取得上传文件的长度
ReDim cs(n) '重定义数组的大小文文件长度
fs = dd.PostedFile.InputStream
fs.Read(cs, 0, n) '用inputstream的方法读取文件到数组
SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@f", System.Data.SqlDbType.Image, n, ParameterDirection.Input, False, 0, 0, "f", DataRowVersion.Current, cs)) '这一步是关键参数不能出错.设置sql语句的参数
SqlCommand1.CommandText = "Insert into table1(f) values(@f)" '上传语句
fs.Close() '下面的我就不解释了.
SqlCn.Open()
SqlCommand1.ExecuteNonQuery()
SqlCn.Close()
End Sub
等我重装系统后把下载部分的代码也贴出来共享.



载部分的:
SqlCommand1.CommandText = "select f from table1 where (id=2)这里id你自己设置
Dim sqlr As SqlClient.SqlDataReader
Dim fs As System.IO.Stream
Dim cs() As Byte
fs = Response.OutputStream()
SqlConnection1.Open()
sqlr = SqlCommand1.ExecuteReader
If sqlr.Read Then
Response.ContentType = "Application/msword"‘这句话千万不能少
'Response.Clear()
cs = sqlr("f")
sqlr.GetBytes(0, 0, cs, 0, UBound(cs))
fs.Write(cs, 0, UBound(cs))
fs.Close()
End If
sqlr.Close()
SqlConnection1.Close()
ok,你已经能在ie中打开这个word文件了。
不过在线编辑后还是要存盘才能上传到数据苦中。

补充如果上传页面编译是提示没有设置到实例删除下面两句话
Dim dd As New HtmlInputFile()
dd.ID = "dd"


HTML在线编辑器的调用方法 http://www.csdn.net/develop/article/15/15214.shtm
另一个在线编辑器:http://www.5aijie.com/html/jianzhan/2.htm


youngby 2003-05-17
  • 打赏
  • 举报
回复
一个简单的ComboBox的原代码
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Lostinet.Sample
{
[
DefaultEvent("TextChanged"),
DefaultProperty("Text"),
]
public class ComboBox:WebControl,INamingContainer,IPostBackDataHandler
{
ListBox lb;
public ComboBox():
base(HtmlTextWriterTag.Input)
{
lb=new ListBox();
lb.Style["position"]="absolute";
lb.Style["display"]="none";
lb.Style["filter"]="progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')";
lb.EnableViewState=false;
Controls.Add(lb);
}

ListItemCollection _coll=new ListItemCollection();
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
]
public ListItemCollection Items
{
get
{
return _coll;
}
}

[
DefaultValue(false),
]
public bool AutoPostBack
{
get
{
return ViewState["AutoPostBack"]==null?false:true;
}
set
{
if(value)
ViewState["AutoPostBack"]=0;
else
ViewState.Remove("AutoPostBack");
}
}


[
DefaultValue(""),
]
public string Text
{
get
{
return Convert.ToString(ViewState["Text"]);
}
set
{
ViewState["Text"]=value;
}
}

[
DefaultValue(0),
]
public int MaxLength
{
get
{
object o=ViewState["MaxLength"];
return o==null?0:(int)o;
}
set
{
ViewState["MaxLength"]=value;
}
}

static private string _scriptBlock;
static protected string ScriptBlock
{
get
{
if(_scriptBlock==null)
{
using(Stream s=typeof(ComboBox).Assembly.GetManifestResourceStream(typeof(ComboBox).FullName+".js"))
{
using(StreamReader sr=new StreamReader(s))
{
_scriptBlock="<script language=jscript>"+sr.ReadToEnd()+"</script>";
}
}
}
return _scriptBlock;
}
}
protected override void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);

Page.RegisterStartupScript(this.UniqueID,"<script>LostinetSampleComboBox_Init('"+this.UniqueID+"','"+lb.UniqueID+"');</script>");

lb.Items.Clear();
for(int i=0;i<Items.Count;i++)
lb.Items.Add(Items[i].Text);

string key=typeof(ComboBox).FullName;
if(!Page.IsClientScriptBlockRegistered(key))
{
Page.RegisterClientScriptBlock(key,ScriptBlock);
}
}

protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Name,this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Value,this.Text,true);
writer.AddAttribute("AutoComplete","Off");
if(MaxLength>0)
writer.AddAttribute(HtmlTextWriterAttribute.Maxlength,MaxLength.ToString(),false);
if(this.AutoPostBack)
writer.AddAttribute(HtmlTextWriterAttribute.Onchange,Page.GetPostBackEventReference(this),false);
}

public void RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}

public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
string v=postCollection[postDataKey];
if(v==Text)
return false;
Text=v;
return true;
}

public event EventHandler TextChanged;

protected virtual void OnTextChanged(EventArgs e)
{
if(TextChanged!=null)
TextChanged(this,e);
}

protected override void LoadViewState(object savedState)
{
Pair p=(Pair)savedState;
base.LoadViewState(p.First);
((IStateManager)_coll).LoadViewState(p.Second);
}

protected override object SaveViewState()
{
return new Pair(base.SaveViewState(),((IStateManager)_coll).SaveViewState());
}

protected override void TrackViewState()
{
base.TrackViewState();
((IStateManager)_coll).TrackViewState();
}
}
}


脚本部分:ComboBox.js


function LostinetSampleComboBox_Init(inputID,listboxID)
{
var tb=document.all(inputID);
var lb=document.all(listboxID);
var isDisplaying=false;

for(var i=lb.options.length;i>0;i--)
lb.options[i]=new Option(lb.options[i-1].text,lb.options[i-1].value);

lb.options[0]=new Option(tb.value,tb.value);

var showlbTimerID=0;
var hidelbTimerID=0;

function ClearTimer()
{
if(hidelbTimerID!=0)
{
clearTimeout(hidelbTimerID);
hidelbTimerID=0;
}
}

function ShowLBSync()
{
var rect=tb.getBoundingClientRect();
lb.style.left=rect.left-document.body.clientLeft+"px";
lb.style.top=(rect.top-document.body.clientTop+tb.offsetHeight)+"px";
lb.style.width=rect.right-rect.left+"px";
lb.style.display="block";

isDisplaying=true;
ClearTimer();
}
function ShowLB()
{
if(showlbTimerID)
return;
ClearTimer();
showlbTimerID=setTimeout(
function(){
showlbTimerID=0;
ShowLBSync();
}
,10);
}
function HideLBSync()
{
lb.style.display="none";
isDisplaying=false;
ClearTimer();
}
function HideLB()
{
if(hidelbTimerID)
return;
ClearTimer();
hidelbTimerID=setTimeout(
function(){
hidelbTimerID=0;
HideLBSync();
}
,10);
}
function FocusToTextBox()
{
lb.selectedIndex=-1;
HideLBSync();
ClearTimer();
tb.focus();
}

tb.attachEvent("onclick",function(){
ShowLB();
});
tb.attachEvent("onblur",function(){
HideLB();
});
tb.attachEvent("onkeydown",function(){
if(event.keyCode==40)
{
document.selection.empty();
ShowLBSync();
lb.selectedIndex=0;
lb.focus();
ClearTimer();
return event.returnValue=!(event.cancelBubble=true);
}
});

lb.attachEvent("onfocus",function(){
ShowLB();
});
lb.attachEvent("onblur",function(){
HideLB();
});
lb.attachEvent("onclick",function(){
if(lb.selectedIndex>-1)
tb.value=lb[lb.selectedIndex].text;
FocusToTextBox();
});
lb.attachEvent("onkeydown",function(){
if(event.keyCode==38&&lb.selectedIndex==0)
{
FocusToTextBox();
}
if(
(
event.keyCode==13||event.keyCode==9
)
&&lb.selectedIndex>-1)
{
tb.value=lb[lb.selectedIndex].text;
FocusToTextBox();
return event.returnValue=!(event.cancelBubble=true);
}
if(event.keyCode==27)
{
FocusToTextBox();
return event.returnValue=!(event.cancelBubble=true);
}
});
}


6,871

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧