首先你看到我的GridView
现在看第5行(星期四)。我有一个日期2015年1月1日,并且还有一个链接按钮,如点击添加。当我点击第5行的Click to add
时获取行的值4.再次点击第6行按钮我得到第5行的值。为什么会这样?如果我犯了任何错误,请帮我解决。我删除了我的数据绑定事件,然后在添加这些事件后得到预期的输出我输出错误。所以问题是我的数据绑定功能。我该如何解决?
我的手机点击事件是
protected void lnkmonth1_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
string id = grdAcademicCalender.DataKeys[row.RowIndex].Value.ToString();
Label lbldate = (Label)row.FindControl("lbldates1");
if (lbldate.Text.Length > 0)
{
DateTime time = Convert.ToDateTime(lbldate.Text);
txtdate.Text = time.ToString("yyyy-MM-dd");
ModalPopupExtender3.Show();
}
else
{
ModalPopupExtender4.Show();
}
bindgridHeader();
bindgrid();
}
我有一个DataBound
protected void grdAcademicCalender_DataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell0 = new TableHeaderCell();
TableHeaderCell cell1 = new TableHeaderCell();
TableHeaderCell cell2 = new TableHeaderCell();
TableHeaderCell cell3 = new TableHeaderCell();
cell0.Text = "Days";
cell0.ColumnSpan = 0;
cell0.BackColor = ColorTranslator.FromHtml("#F5BCA9");
row.Controls.Add(cell0);
if (!string.IsNullOrEmpty(lblmonth1.Text))//January 2015
{
cell1.Text = lblmonth1.Text;
cell1.ColumnSpan = 3;
cell1.BackColor = ColorTranslator.FromHtml("#F5BCA9");
row.Controls.Add(cell1);
}
else
{
}
if (!string.IsNullOrEmpty(lblmonth2.Text))//February 2015
{
cell2.Text = lblmonth2.Text;
cell2.ColumnSpan = 3;
cell2.BackColor = ColorTranslator.FromHtml("#F5BCA9");
row.Controls.Add(cell2);
}
else
{
}
if (!string.IsNullOrEmpty(lblmonth3.Text))//March 2015
{
cell3.Text = lblmonth3.Text;
cell3.ColumnSpan = 3;
cell3.BackColor = ColorTranslator.FromHtml("#F5BCA9");
row.Controls.Add(cell3);
}
grdAcademicCalender.HeaderRow.Parent.Controls.AddAt(0, row);
}
我的aspx是
<asp:GridView ID="grdAcademicCalender" Width="1500" runat="server" HeaderStyle-BackColor="Wheat" PageSize="40" DataKeyNames="ID"
AutoGenerateColumns="False" ShowHeader="false" OnDataBound="grdAcademicCalender_DataBound" OnRowDataBound="grdAcademicCalender_RowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblshortdate" runat="server" Text='<%#Eval("ShortName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbldates1" runat="server" Text='<%#Eval("Dates1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblmonth1" runat="server" Text='<%#Eval("MonthNumber1") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="1%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Linkbutton ID="lblevent1" runat="server" Text='<%#Eval("EventField1") %>'></asp:Linkbutton>
<asp:Linkbutton ID="lnkmonth1" Width="140" runat="server" OnClick="lnkmonth1_Click" Text="Click to add"></asp:Linkbutton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
如果很难做到,那么当我点击cell1(递增的单元格值)时,帮助我获取cell2值。