新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → datagrid编辑xml的求助 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 11652 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: datagrid编辑xml的求助 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     001jaye 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:52
      门派:XML.ORG.CN
      注册:2004/9/25

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给001jaye发送一个短消息 把001jaye加入好友 查看001jaye的个人资料 搜索001jaye在『 Dot NET,C#,ASP,VB 』的所有贴子 引用回复这个贴子 回复这个贴子 查看001jaye的博客楼主
    发贴心情 datagrid编辑xml的求助

    datagrid编辑xml的求助
    使用vb.net
    当然c#也行
    如何利用datagrid来编辑xml文档,
    最大的难点:
    1。要求datagrid在窗体load后应该有许多行和列,以建立一个新的xml。
    2。如果通过点击字段名或其他的方式方便地来改变,增加,删除字段。
      qq:1251390
    email:liuzhehong@tom.com

       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/9/25 14:40:00
     
     yudith 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:13
      积分:112
      门派:XML.ORG.CN
      注册:2004/5/16

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给yudith发送一个短消息 把yudith加入好友 查看yudith的个人资料 搜索yudith在『 Dot NET,C#,ASP,VB 』的所有贴子 引用回复这个贴子 回复这个贴子 查看yudith的博客2
    发贴心情 
    给你份源码
    aspx文件:
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Globalization" %>
    <script Language="c#" runat="server">
      void Page_Load(object sender, EventArgs e)
      {
        if (!(Page.IsPostBack))
        {
          EventData.DataSource = LoadMyCalendarData();
          EventData.DataBind();
        }
      }

      protected DataSet LoadMyCalendarData()
      {
         string sourceXml = Server.MapPath("MyCalendar.xml");
          if (!(File.Exists(sourceXml)))
          {
             return null;
          }
         DataSet cachedDataSet = (DataSet)Session["MyCalendarData"];
         if (!(cachedDataSet == null))
         {
            return cachedDataSet;
         }
        DataSet dataSet = new DataSet();
        try
        {
           dataSet.ReadXml(sourceXml);
           Session["MyCalendarData"] = dataSet;
        }
        catch (Exception e)
        {
           ErrorMessage.Text = e.Message;
           dataSet = null;
        }
        return dataSet;
      }

      void DEDR_Edit(object sender, DataGridCommandEventArgs e)
      {
         EventData.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
         EventData.DataSource = LoadMyCalendarData();
         EventData.DataBind();
      }

      void DEDR_Update(object sender, DataGridCommandEventArgs e)
      {
         DataSet dataSet  = LoadMyCalendarData();
         int row = Convert.ToInt32(e.Item.ItemIndex);
         TextBox EditText = null;
         EditText = (TextBox)e.Item.FindControl("txtShortDesc");
         dataSet.Tables[0].Rows[row]["ShortDesc"] = EditText.Text;
         EditText = (TextBox)e.Item.FindControl("txtDetailDesc");
         dataSet.Tables[0].Rows[row]["DetaiLDesc"] = EditText.Text;
         EditText = (TextBox)e.Item.FindControl("txtEventDate");
         dataSet.Tables[0].Rows[row]["EventDate"]= EditText.Text;
         EditText = (TextBox)e.Item.FindControl("txtStartTime");
         dataSet.Tables[0].Rows[row]["StartTime"] = EditText.Text;
         EditText = (TextBox)e.Item.FindControl("txtEndTime");
         dataSet.Tables[0].Rows[row]["EndTime"] = EditText.Text;
         dataSet.WriteXml(Server.MapPath("MyCalendar.xml"));
         Session["MyCalendarData"] = null;
         EventData.EditItemIndex = -1;
         EventData.DataSource = LoadMyCalendarData();
         EventData.DataBind();
      }

      void DEDR_Cancel(object sender, DataGridCommandEventArgs e)
      {
        EventData.EditItemIndex = -1;
        Session["MyCalendarData"] = null;
        EventData.DataSource = LoadMyCalendarData();
        EventData.DataBind();
      }

      void DEDR_Delete(object sender, DataGridCommandEventArgs e)
      {
        DataSet dataSet = LoadMyCalendarData();
        int row = Convert.ToInt32(e.Item.ItemIndex);
        dataSet.Tables[0].Rows[row].Delete();
        dataSet.WriteXml(Server.MapPath("MyCalendar.xml"));
        Session["MyCalendarData"] = null;
        EventData.EditItemIndex = -1;
        EventData.DataSource = LoadMyCalendarData();
        EventData.DataBind();
      }

      void DEDR_Add(object sender, EventArgs e)
      {
        DataSet dataSet = LoadMyCalendarData();
        DataRow newRow;
        newRow = dataSet.Tables[0].NewRow();
        newRow["ShortDesc"] = "";
        newRow["DetailDesc"] = "";
        newRow["EventDate"] = "";
        newRow["StartTime"] = "";
        newRow["EndTime"] = "";
        dataSet.Tables[0].Rows.Add(newRow);
        dataSet.WriteXml(Server.MapPath("MyCalendar.xml"));
        Session["MyCalendarData"] = null;
        EventData.DataSource = LoadMyCalendarData();
        EventData.DataBind();
        EventData.EditItemIndex = EventData.Items.Count - 1;
        EventData.DataSource = LoadMyCalendarData();
        EventData.DataBind();
      }
    </script>


    <html>
      <body>
        <form runat="server">
          <asp:Label id="ErrorMessage" runat="server" /><br/>
          <asp:LinkButton OnClick="DEDR_Add" Text="Add new event"
               runat="server"/><br/>
          <asp:DataGrid id="EventData"
               AutoGenerateColumns="false" width="100%" runat="server"
               OnEditCommand="DEDR_Edit"
               OnUpdateCommand="DEDR_Update"
               OnCancelCommand="DEDR_Cancel"
               OnDeleteCommand="DEDR_Delete">
            <HeaderStyle ForeColor="White" BackColor="DodgerBlue"
                         Font-Bold="true"/>
            <ItemStyle BackColor="White"/>
            <AlternatingItemStyle BackColor="Gainsboro"/>
            <Columns>

              <asp:TemplateColumn HeaderText="Date">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "EventDate") %>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="txtEventDate" Size="25";
                       Text='<%# DataBinder.Eval(Container.DataItem,"EventDate") %>'
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>

              <asp:TemplateColumn HeaderText="Event">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "ShortDesc") %>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="txtShortDesc" Size="25";
                       Text='<%# DataBinder.Eval(Container.DataItem,"ShortDesc") %>'
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>

              <asp:TemplateColumn HeaderText="Description">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "DetailDesc") %>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="txtDetailDesc" Size="50"
                     Text='<%# DataBinder.Eval(Container.DataItem, "DetailDesc") %>'
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>

              <asp:TemplateColumn HeaderText="Start Time">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "StartTime") %>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="txtStartTime" Size="7"
                       Text='<%# DataBinder.Eval(Container.DataItem, "StartTime") %>'
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>

              <asp:TemplateColumn HeaderText="EndTime">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "EndTime") %>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="txtEndTime" Size="7"
                       Text='<%# DataBinder.Eval(Container.DataItem, "EndTime") %>'
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>

              <asp:TemplateColumn>
                <ItemTemplate>
                  <asp:LinkButton CommandName="Edit"   Text="Edit"
                       runat="server"/>
                  <asp:LinkButton CommandName="Delete" Text="Delete"
                       runat="server"/>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:LinkButton CommandName="Cancel" Text="Cancel"
                       runat="server"/>
                  <asp:LinkButton CommandName="Update" Text="Update"
                       runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>
            </Columns>
        </asp:DataGrid>
        </form>
      </body>
    </html>

    MyCalendar.xml:
    <?xml version="1.0" standalone="yes"?>
    <MyCalendar>
      <Event>
        <ShortDesc>Gig in Portland - Jazz Club</ShortDesc>
        <DetailDesc>This should be fun - playing J &amp; T again - be sure to bring the charts.</DetailDesc>
        <EventDate>2002/07/02</EventDate>
        <StartTime>6:00PM</StartTime>
        <EndTime>11:30PM</EndTime>
      </Event>
      <Event>
        <ShortDesc> Rehearsal - Brigadoon</ShortDesc>
        <DetailDesc>Community Theatre orchestra rehearsal - bring mutes.</DetailDesc>
        <EventDate>2002/07/14</EventDate>
        <StartTime>3:30PM</StartTime>
        <EndTime>6:30PM</EndTime>
      </Event>
      <Event>
        <ShortDesc>.NET Training Class</ShortDesc>
        <DetailDesc>This should be fun - we'll explore some of the really cool stuff, like ASP.NET server controls and Web Services.</DetailDesc>
        <EventDate>2002/07/17</EventDate>
        <StartTime>8:00AM</StartTime>
        <EndTime>4:30PM</EndTime>
      </Event>
      <Event>
        <ShortDesc>Writing Workshop for Musical Project with Gregg</ShortDesc>
        <DetailDesc>We're going to brainstorm some ideas and see if we can come up with something great.  We're off to a good start.</DetailDesc>
        <EventDate>2002/07/19</EventDate>
        <StartTime>10:00AM</StartTime>
        <EndTime>6:30PM</EndTime>
      </Event>
      <Event>
        <ShortDesc>Community Band</ShortDesc>
        <DetailDesc>Central park - we'll play everything from standards to shows tunes to classical to marches - you name it.  People bring their lawn chairs, eat their dinner, kids play - a great time!</DetailDesc>
        <EventDate>2002/07/24</EventDate>
        <StartTime>7:00PM</StartTime>
        <EndTime>9:00PM</EndTime>
      </Event>
      <Event>
        <ShortDesc>Jam Session at the Beach</ShortDesc>
        <DetailDesc>Bring more food this time and the crab nets - and the instruments!  We'll might stay for a week or so depending on the weather.</DetailDesc>
        <EventDate>2002/07/21</EventDate>
        <StartTime>8:00AM</StartTime>
        <EndTime>11:30PM</EndTime>
      </Event>
      <Event>
        <ShortDesc>Rob's Birthday!</ShortDesc>
        <DetailDesc>Nothing too fancy - just friends and family.  Hope it's a nice day - bike ride would be fun.</DetailDesc>
        <EventDate>2002/07/30</EventDate>
        <StartTime>6:09PM</StartTime>
        <EndTime>11:30PM</EndTime>
      </Event>
    </MyCalendar>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/9/26 21:40:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/12/27 19:47:26

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    109.375ms