我编写了Gridview代码,如下面的代码行
<div class="overflowX">
<asp:GridView ID="grdView" AutoGenerateColumns="false" BorderWidth="0" runat="server" CssClass="table">
<Columns>
<asp:TemplateField HeaderText="Non-Resident License">
<ItemTemplate>
<asp:Label ID="lblJurisdiction" runat="server" Text='<%# Container.DataItem %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Effective Date">
<ItemTemplate>
<asp:TextBox ID="txtEffectiveDate" style="padding:12px 5px;" placeholder="(mm/dd/yyyy)" CssClass="datepiker" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
在cs文件中
private void FillJurisdictionGrid(string Jurisdiction, string IssueDate)
{
Jurisdiction = "Alabama, Alaska, Arizona";
IssueDate = "12/10/2015";
if (Jurisdiction != "")
{
grdView.Visible = true;
grid.Visible = true;
txtJurisdiction.Enabled = false;
string[] jurisdictionData = Jurisdiction.Split(',');
grdView.DataSource = jurisdictionData;
grdView.DataBind();
}
else
{
grid.Visible = false;
grdView.Visible = false;
}
}
我希望Grid看起来像
非居民许可 - 生效日期
阿拉巴马州 - 12/10/2015
阿拉斯加 - 2015年12月10日
亚利桑那州 - 12/10/2015
我希望该日期在网格视图的txtEffective`日期文本框中的所有行中显示相同。
请帮帮我。
答案 0 :(得分:0)
protected void Page_Load(object sender, EventArgs e)
{
string Jurisdiction = "Alabama, Alaska, Arizona";
string IssueDate = "12/10/2015";
FillJurisdictionGrid(Jurisdiction, IssueDate);
}
private void FillJurisdictionGrid(string Jurisdiction, string IssueDate)
{
if (Jurisdiction != "")
{
grdView.Visible = true;
//grid.Visible = true;
//txtJurisdiction.Enabled = false;
string[] jurisdictionData = Jurisdiction.Split(',');
grdView.DataSource = jurisdictionData;
grdView.DataBind();
for (int i = 0; i < grdView.Rows.Count; i++)
{
TextBox txtEffectiveDate = (TextBox)grdView.Rows[i].FindControl("txtEffectiveDate");
txtEffectiveDate.Text = IssueDate;//By chance you want to pass the Textbox Value
}
}
else
{
// grid.Visible = false;
grdView.Visible = false;
}
}
答案 1 :(得分:0)
试试这个:
` private void FillJurisdictionGrid()
{
string Jurisdiction = "Alabama, Alaska, Arizona";
string IssueDate = "12/10/2015";
if (Jurisdiction != "")
{
grdView.Visible = true;
string[] jurisdictionData = Jurisdiction.Split(',');
DataTable dt = new DataTable();
dt.Columns.Add("Jurisdiction");
dt.Columns.Add("IssueDate");
for (int i = 0; i < jurisdictionData.Length; i++)
{
DataRow toInsert = dt.NewRow();
dt.Rows.InsertAt(toInsert, i);
dt.Rows[i]["Jurisdiction"] = jurisdictionData[i].ToString();
dt.Rows[i]["IssueDate"] = IssueDate;
}
grdView.DataSource = jurisdictionData;
grdView.DataBind();
}
else
{
grdView.Visible = false;
}
}`