如何将data-info属性添加到动态生成的单选按钮

时间:2013-09-05 08:18:23

标签: c# asp.net jquery asp.net-ajax

我正在添加一个生成动态的单选按钮。现在我想将data-info属性设置为在浏览器中动态生成的Input [type = radio]按钮。我在使用带有c#的asp.net。请提供替代方案如何添加此选项。紧急

if (ds.Tables.Count > 0)
{
    if (ds.Tables[0].Rows.Count > 0)
    {
        int iCnt = 0;
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            Table tblQsn = new Table();

            //.....Begin Text Qsn Creation.....//
            tblQsn.Width = 500;

            TableRow trQsn = new TableRow();
            iRowCounter++;
            trQsn.ID = "Row_" + iRowCounter.ToString();

            TableCell tcQsn = new TableCell();
            TableCell tcQsnSNo = new TableCell();

            tcQsn.CssClass = "Label";
            tcQsn.BackColor = System.Drawing.Color.Gainsboro;
            tcQsn.Font.Bold = true;
            tcQsn.Text = ds.Tables[0].Rows[i][1].ToString();
            tcQsn.Width = Unit.Percentage(99.5);
            iCellCounter++;
            tcQsn.ID = "Cell_" + iCellCounter.ToString();

            tcQsnSNo.CssClass = "Label";
            tcQsnSNo.Attributes.Add("valign", "top");
            tcQsnSNo.BackColor = System.Drawing.Color.Gainsboro;
            tcQsnSNo.Font.Bold = true;
            tcQsnSNo.Width = Unit.Percentage(0.5);
            iCellCounter++;
            tcQsnSNo.ID = "Cell_" + iCellCounter.ToString();
            iCnt++;
            tcQsnSNo.Text =ContentIndex.ToString() + ".";

            trQsn.Cells.Add(tcQsnSNo);
            trQsn.Cells.Add(tcQsn);
            tblQsn.Rows.Add(trQsn);

            int rcnt = i;
            int iOptCnt = 0;
            string sStatus = "N";

            while ((rcnt >= 0) && (rcnt < ds.Tables[0].Rows.Count))
            {
                if (ds.Tables[0].Rows[rcnt][2].ToString() == ds.Tables[0].Rows[i][2].ToString())
                {
                    if (sStatus == "N")
                    {
                        sStatus = "Y";
                    }

                    TableRow trQsnOpt = new TableRow();
                    iRowCounter++;
                    trQsnOpt.ID = "Row_" + iRowCounter.ToString();
                    TableCell tcQsnOpt = new TableCell();
                    tcQsnOpt.CssClass = "Label";
                    iCellCounter++;
                    tcQsnOpt.ID = "Cell_" + iCellCounter.ToString();
                    tcQsnOpt.Attributes.Add("valign", "top");
                    tcQsnOpt.VerticalAlign = VerticalAlign.Middle;
                    TableCell tcQsnOptSNo = new TableCell();
                    tcQsnOptSNo.CssClass = "Label";
                    iCellCounter++;
                    tcQsnOptSNo.ID = "Cell_" + iCellCounter.ToString();

                    iOptCnt++;
                    RadioButton oRbOptions = new RadioButton();
                    oRbOptions.GroupName = ds.Tables[0].Rows[rcnt][2].ToString() + "_Group";
                    oRbOptions.Text = ds.Tables[0].Rows[rcnt][3].ToString().Trim();
                    iRbTCounter++;

                    oRbOptions.ID = ds.Tables[0].Rows[i][0].ToString() + "_" + ds.Tables[0].Rows[rcnt][2].ToString() + "_" + "Option" + iOptCnt.ToString() + "_" + iRbTCounter.ToString();


                    oRbOptions.CssClass = "Label";
                    tcQsnOpt.Controls.Add(oRbOptions);
                    tcQsnOptSNo.Text = iOptCnt.ToString() + ".";
                    trQsnOpt.Cells.Add(tcQsnOptSNo);
                    trQsnOpt.Cells.Add(tcQsnOpt);
                    rcnt++;
                    //.....Add Option Image.....//
                    tblQsn.Rows.Add(trQsnOpt);
                }
                else
                    break;
            }
        i = rcnt - 1;
        PlaceHolder PlPreview = (PlaceHolder)e.Item.FindControl("PlPreview");
        PlPreview.Controls.Add(tblQsn);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

使用oRbOptions.Attributes.Add("data-info", "someValue");

MSDN LINK