如何拆分gridview单元格并显示到标签 [英] how to split gridview cell and display in to label
问题描述
在Gridview中记录如下
选择(按钮)可用座位
点击这里MFA :日期 - 2015年7月22日至2015年7月25日
当用户点击选择按钮时可用座位日期将在标签中显示如下
lblresult.Text = MFA:日期 - 2015年7月22日至2015年7月25日
我的代码如下
protected void gvPkgcbndate_SelectedIndexChanged1(object sender,EventArgs e)
{
lblresult.Text = gvPkgcbndate.SelectedRow.Cells [2] .Text;
}
我想在标签中显示可用座位如下
2015年7月22日
i不想要所有的价值。 MFA:日期 - 2015年7月22日至2015年7月25日
我怎样才能在asp.net中使用c#。
In Gridview record as as follows
Select(Button) Available Seats
Click Here MFA : Date - 22 Jul 2015 To - 25 Jul 2015
When user click select button Available seats date will be displayed in the label as follows
lblresult.Text = MFA : Date - 22 Jul 2015 To - 25 Jul 2015
My code as follows
protected void gvPkgcbndate_SelectedIndexChanged1(object sender, EventArgs e)
{
lblresult.Text = gvPkgcbndate.SelectedRow.Cells[2].Text;
}
I want to display the Available seats in the label as follows
22 Jul 2015
i do not want all the value. MFA : Date - 22 Jul 2015 To - 25 Jul 2015
for that how can i do in asp.net using c#.
推荐答案
如果你的字符串看起来总是相同,那么将它拆分为位置(带有delimiter-char) - 。
现在你得到一个字符串数组,哪个元素[1包含第一个日期,它的元素[2]包含第二个日期。两者都是字符串。也许您还需要在这些子字符串的开头和结尾删除空格。
If your string Looks allways the same then split it at Position (with delimiter-char) "-".
Now you get back a string-array which element[1] contains the first date and it's element[2] contains the second date. Both as string. Perhaps you also need to delete spaces at the beginning and the end of those sub-strings.
这篇关于如何拆分gridview单元格并显示到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!