0

I'm trying to build a grid view dynamically based on the table name. So, I get columns, length, data type, and primary and foreign keys. Then I determine using a developed UI kind of TemplateField based on provided columns.

I use two XML documents. one of them has the formal TemplateField with many types of controls such as TemplateField with text box, with drop-down list, ..etc. the other XML document is to build the grid view itself.

I successfully transferred what I need from one XML to another. however, some peace can't be able to transfer --> especially parts of data-binding for example like this (checked='<%# Bind("IsRegistered") %>')

All I need is to know how to include something like this '<%# Bind("IsRegistered") %>' inside XML document

My C# code (and no problem with it but to know how to inject data-binding tags in XML doc)

    XmlDocument Formal_TemplateField = new XmlDocument();
    XmlDocument BuildMyGridView = new XmlDocument(); 
    bool first_Use = false;
    private void Build_XML(string TemplateField, string Field_Name)
    {
        Formal_TemplateField.Load(Server.MapPath("~/Formal_TemplateField.xml"));
        BuildMyGridView.Load(Server.MapPath("~/BuildMyGridView.xml"));
        if (first_Use == false) // clean all xml old data
        {
            XmlNode root = BuildMyGridView.DocumentElement.GetElementsByTagName("Columns")[0];
            root.RemoveAll();
            first_Use = true;
        }

        XmlNode NEW_NOOD = BuildMyGridView.ImportNode(Formal_TemplateField.DocumentElement[TemplateField].FirstChild, true);
        if (Field_Name != null)
        {
            NEW_NOOD.Attributes["HeaderText"].Value = "Header_" + Field_Name;
            NEW_NOOD.Attributes["SortExpression"].Value = Field_Name;
            NEW_NOOD["EditItemTemplate"].FirstChild.Attributes["Text"].Value = "&lt;%# Bind(&apos;" + Field_Name + "&apos;)%&gt;";   // '<%# Bind("DateOfBirth")%>' 
            NEW_NOOD["HeaderTemplate"].FirstChild.Attributes["Text"].Value = Field_Name;
            NEW_NOOD["ItemTemplate"].FirstChild.Attributes["Text"].Value = "&lt;%# Bind(&apos;" + Field_Name + "&apos;)%&gt;";
        }
        BuildMyGridView.DocumentElement.GetElementsByTagName("Columns")[0].AppendChild(NEW_NOOD);

        BuildMyGridView.Save(Server.MapPath("~/BuildMyGridView.xml"));
    }

Here is minified view of XmlDocument Formal_TemplateField

 <Formal_TemplateField>
      <TextBox_Dates>
         <asp:TemplateField>
              bla bla bla
         </asp:TemplateField>
      </TextBox_Dates>

      <CheckBox>
        <asp:TemplateField>
              bla bla bla
        </asp:TemplateField>
      </CheckBox>

      <DropDownList>
        <asp:TemplateField>
          <EditItemTemplate>
              bla bla bla
          </EditItemTemplate>
          <HeaderTemplate>
               bla bla bla
          </HeaderTemplate>
          <ItemTemplate>
            <asp:Label ID="Label4" runat="server" Text=''></asp:Label>  <-- look at this for example
          </ItemTemplate>
        </asp:TemplateField>
      </DropDownList>

Simply, I would like to convert for example DropDownList section to the next example with data binding

      <DropDownList>
        <asp:TemplateField HeaderText="Gender_ID" SortExpression="Gender_ID">
          <EditItemTemplate>
             bla bla bla
          </EditItemTemplate>
          <HeaderTemplate>
             bla bla bla
          </HeaderTemplate>
          <ItemTemplate>
            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Gender_ID") %>'></asp:Label>
          </ItemTemplate>
        </asp:TemplateField>
      </DropDownList>
  • 1
    Does this answer your question? [How do I include &, <, > etc in XML attribute values](https://stackoverflow.com/questions/5709232/how-do-i-include-etc-in-xml-attribute-values) – oleksa Mar 25 '20 at 10:29
  • See https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references – jdweng Mar 25 '20 at 12:05

0 Answers0