0

GridViewInsertEventArgs.NewValuesTemplateField から値が返されなかったため、この混乱を開始しました

DropDownListctl00$MainContent$GridView1$ctl13$ctl07にアクセスしようとすると、その周りのすべてのアイテムが見つかりますが、

ありませんe.Row.Controls[7].Controls[0];

e.Row.Controls[1].Controls[0] returns ctl00$MainContent$GridView1$ctl13$ctl01
e.Row.Controls[2].Controls[0] returns ctl00$MainContent$GridView1$ctl13$ctl02
e.Row.Controls[3].Controls[0] returns ctl00$MainContent$GridView1$ctl13$ctl03

など 7 のみが機能しません

 also tried 

e.Row.Cells[7].Controls[0]

サーバーが単にコントロールを認識していないようです

<table class="table" cellspacing="0" cellpadding="30" rules="all" border="1" id="MainContent_GridView1" style="color:#333333;border-color:Silver;border-style:Double;width:100%;border-collapse:collapse;">
    <tr style="color:White;background-color:#507CD1;font-weight:bold;">
        <th scope="col">Action</th>
        <th scope="col">SystemIdentifier_1</th>
        <th scope="col">SystemName_1</th>
        <th scope="col">Description_1_1</th>
        <th scope="col">DefaultValue_1</th>
        <th scope="col">DefaultDeviceTypeRef_1</th>
        <th scope="col">SqlDbType_1</th>
        <th scope="col">MaxParamSize_1</th>
    </tr>
    <tr style="background-color:White;">
        <td><a href="javascript:__doPostBack(&#39;ctl00$MainContent$GridView1$ctl13$ctl00&#39;,&#39;&#39;)" style="color:#333333;">Insert</a>&nbsp;</td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl03" type="text" title="SystemIdentifier_1" /></td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl04" type="text" title="SystemName_1" /></td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl05" type="text" title="Description_1_1" /></td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl06" type="text" title="DefaultValue_1" /></td>
        <td>
            <select name="ctl00$MainContent$GridView1$ctl13$ctl07">
                <option value="1">TC4020G</option>
                <option value="2">Warehouse Station</option>
                <option value="3">IssueStation</option>
                <option value="4">PersonalizationStation</option>
                <option value="5">Smart Card</option>
                <option value="6">Loader</option>
                <option value="7">Server Service</option>
            </select>
        </td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl08" type="text" title="SqlDbType_1" /></td>
        <td><input name="ctl00$MainContent$GridView1$ctl13$ctl09" type="text" title="MaxParamSize_1" /></td>
    </tr>

私のコンボボックステンプレート:

  public class ComboBoxTemplate : ITemplate
    {

        ListItemType _type;
        string _colName;
        Dictionary<string, string> _items;

        public ComboBoxTemplate(ListItemType type, string colname,Dictionary<string,string> items)
        {
            _type = type;
            _colName = colname;
            _items = items;
        }

        public void InstantiateIn(Control container)
        {
            try
            {
                switch (_type)
                {
                    case ListItemType.Item:

                        Label l = new Label();
                        l.DataBinding += l_DataBinding;
                        container.Controls.Add(l);

                        break;
                    case ListItemType.EditItem:

                        DropDownList ddl = new DropDownList();
                        foreach (var obj in _items)
                        {
                            ddl.Items.Add(new ListItem(obj.Value, obj.Key));
                        }
                        ddl.DataBinding += l_DataBinding;
                        container.Controls.Add(ddl);


                        break;
                }
            }
            catch (Exception ex)
            {

                return;
            }

        }

        void l_DataBinding(object sender, EventArgs e)
        {                 
            try
                    {
            GridViewRow container;
            object dataValue;
            switch (sender.GetType().ToString())
            {
                case "System.Web.UI.WebControls.Label":
                    Label label = (Label)sender;
                    container = (GridViewRow)label.NamingContainer;
                    dataValue = DataBinder.Eval(container.DataItem, _colName);
                    if (dataValue != DBNull.Value)
                    {
                        if (_items.ContainsKey(dataValue.ToString()))
                        {
                            label.Text = _items[dataValue.ToString()];
                        }
                        else
                        {
                            label.Text = dataValue.ToString();
                        }
                    }
                    break;
                //use the DatePickerControl.DatePicker type instead of ddl
                case "System.Web.UI.WebControls.DropDownList":




                    DropDownList ddl = (DropDownList)sender;
                    container = (GridViewRow)ddl.NamingContainer;

                    dataValue = DataBinder.Eval(container.DataItem, _colName);

                    if (dataValue != DBNull.Value)
                    {
                        ddl.SelectedValue = dataValue.ToString();

                    }
                    break;
                    }    


            }
            catch (Exception ex)
            {

                return;
            }
        }
    }

このようなコンボボックスを作成する(データバインディング時):

                var fkdata = Model.GridProvider.GetForgienKeyData(x);
                templateColumn.EditItemTemplate = new ComboBoxTemplate(ListItemType.EditItem, column.ColumnName, fkdata);
                templateColumn.ItemTemplate = new ComboBoxTemplate(ListItemType.Item, column.ColumnName, fkdata);
4

0 に答える 0