English 中文(简体)
如何根据条件在GridView中查证Box?
原标题:How to Check the CheckBox in a GridView based on Condition?

i am a beginner. I have four textbox fields for ItemName, ItemDescription, Length and Quantity. One radiobuttonlist and its listitems are FixedLength and Random Length. One button field called Submit and one gridview.

在GridView I中,有4个约束栏和1个模板栏,如项目Name、项目说明、Length、定量和IsFixed_f(外地)。 我在“Fixed_f”现场的GredView模板栏中增加了一个检查箱。

在进入所有文本框领域之后,我不得不在无线电台名单上选择一个清单。 完成这些工作之后。 如果我进入下游子,将在GridView下展示的文本箱中的所有数值,如果固定清单项目是用其他方式选择的核对箱,则将核对相应的栏目名称和核对箱。 检查应该是假的。 如何做到这一点?

在Button Click事件中,我也使用了这种说法。

        DataRow DR = null;
        DR = datatable.NewRow();
        DR["ItemName"] = DSItemName.Text.Trim();
        DR["Description"] = txtItemDescription.Text.Trim();
        DR["Length"] = txtLength.Text.Trim();
        DR["Quantity"] = txtQuantity.Text.Trim();
        datatable.Rows.Add(DR);
        GridView.DataSource = datatable;
        GridView.DataBind();

But I dont know How to Check the CheckBox and Displays it in the GridView. Please give suggestions. If I use the following code, It displays the text "true" with the CheckBox in the GridView.

        foreach (GridViewRow GVR in gridview.Rows)
        {
            CheckBox cb = (CheckBox)GVR.FindControl("cbIsFixed_f");

            if (cb != null && radiobuttonlist.SelectedItem.Value == "Fixed Length")
            {
                cb.Checked = true;
            }
            else
            {
                cb.Checked = false;
            }
            DR["IsFixed_f"] = cb.Checked;
        }
最佳回答

我回答这个问题。

 DR["IsFixed_f"] = radiobuttonlist.SelectedItem.Value == "Fixed Length" ?true : false;

感谢各位作答。

问题回答

您可以撰写一份活动书,供网上浏览网上查阅。 在这种情况下,你需要找到检查箱栏并检查或检查。

例如:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
  CheckBox c = e.Row.Cells[4].FindControl("YourCheckboxId");
  if(c != null && e.Row.DataItem["sFixed_f"] == true)
  {
    c.Checked = true;
  }
}

我不清楚如何摆脱数据集——我假定你指的是数据可用性。 此外,我希望您的表Schema中有一个一栏,用于您的Fixed_f数值。

If your tableSchema has an extra column for your IsFixed_f values you may bind those values by using a checkBoxField.

你提到模板 实地我假定,您的表格没有确定Fixed_f。 在这种情况下,你可以人工将本栏添加到您的图表中。

将你的“Fixed_f Value to a specificeck Box (in a new gridviewrow) without storing it some where (dataset/table?!) - 对我来说似乎是不可能的......

希望可能有助于——如果不是的话,请详细说明你的问题!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签