星期三 星期四 星期五 星期六 星期日 星期一 星期二
医生1 1 1
医生2 1 1 1上面是显示 样式
数据库中 的表是这样的 doctorName 这里记录的医生姓名的数据 下面的 星期几 里面如果填入1 表示 星期几可以挂号 否则为空
星期一
星期二
星期三
星期四
星期五
星期六
星期日请问如何 邦定 实现我最上面的哪种要是 同时 使 数字1的项为可点击的连接 点击的同时 能 获得 所在行 与列的值 。传递到下一个页面。
解决方案 »
- C# winform的图片移动问题~~~graphics
- 关于datawindow.net 2.5
- DropDownList 的问题
- static 在C#中应用的利与弊
- F:\net_web\Lx_lltjxt\CreateImage\CreateImage.aspx.resx 文件“CreateImage.aspx.resx”的资源转换失败。有多个根元素。 行 43,位置 2
- ?如何在自定义用户控件中消毁控件自身?执行 this.Dispose()会报““child”不是此父级的子控件。”的提示!
- 关于panel控件
- (TextBox)Report.Rows[iRowCnt].Cells[7].Controls[0] 为什么无法修改?!
- 求c#写的ftp源码,需要达到cuteftp功能,能用就给100分
- 第一个工程加载第二个工程的时候,只需要第二个工程的窗体在后台运行
- 如何在web服务器上自动运行程序
- 关于继承
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb = (Label)e.Row.FindControl("lb"); lb.text就是这一行的医生名字,你在这里:
hyplink hy1=(hyplink)e.Row.FindControl("hyplink1");
设置hy1的属性
hyplink hy2=(hyplink)e.Row.FindControl("hyplink2");
设置hy2的属性
.....
....
}
}这个上面 要如何定义啊 我不了解格式 倒着 写不出来..... 写出来 也是错的 每次看代码 都是用穷举法.. 试验 ... 试验的头都大了 最后还没有好结果...
这样就可以吧
<asp:ImageButton AlternateText='<%#Eval("AccessoriesId") %>' Visible='<%#(int)Eval("AccessoriesId")==0?false:true %>' ImageUrl="~/images/i.p.attach.gif" ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" />
</ItemTemplate>上面做的是一个如果有值则显示图片.否则不显示.数据绑定的时候你将一些需要的值也绑定到这个控件的其他属性上面.然后取值给你个思路...
{
string[] a = new string[8];
string[] b = new string[8];
for (int i = 0; i < 8; i++)
{
a[i] = date(System.DateTime.Now.AddDays(i));
b[i] = dateR(System.DateTime.Now.AddDays(i));
}
DataSet ds = null;
string sql = " select * from 医生出诊时间表 ";//sql语句,然后用它自动绑定GridView
ds = hp.ReturnDataSet(sql, "医生出诊时间表");
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.HeaderRow.Cells[0].Text ="医生姓名";
GridView1.HeaderRow.Cells[1].Text = b[1] +a[1];
GridView1.HeaderRow.Cells[2].Text = b[2] +a[2];
GridView1.HeaderRow.Cells[3].Text = b[3] +a[3];
GridView1.HeaderRow.Cells[4].Text = b[4] +a[4];
GridView1.HeaderRow.Cells[5].Text = b[5] +a[5];
GridView1.HeaderRow.Cells[6].Text = b[6] +a[6];
GridView1.HeaderRow.Cells[7].Text = b[7] +a[7];
}
private string date(DateTime d)
{
string str = d.DayOfWeek.ToString();
string dates = "";
switch (str)
{
case "Monday": dates = "星期一"; break;
case "Tuesday": dates = "星期二"; break;
case "Wednesday": dates = "星期三"; break;
case "Thursday": dates = "星期四"; break;
case "Friday": dates = "星期五"; break;
case "Saturday": dates = "星期六"; break;
case "Sunday": dates = "星期日"; break;
}
return dates;
} private string dateR(DateTime r)
{
string str = r.ToLongDateString(); return str;
}
protected void LinkButtons_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent;
GridViewRow gvr = (GridViewRow)dcf.Parent;
GridView1.SelectedIndex = gvr.RowIndex;
string name = GridView1.SelectedRow.Cells[0].Text.ToString();
int com = GridView1.SelectedRow.Cells.GetCellIndex((TableCell)dcf);
string riqi = GridView1.HeaderRow.Cells[com].Text;
Response.Redirect("default.aspx?doctor=" + name + "&riqi=" + riqi);
}我这个代码能获取行值 列值 同时表头能 按照我的要求显示 但是 数据填充变成死的了...
星期几下面显示的数据都成一样的了 等于绑定数据又变成死的了
<Columns>
<asp:BoundField DataField="医生" HeaderText="医生" />
</Columns>
</asp:GridView>
后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class admin_Default : System.Web.UI.Page
{
static SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
string[] a = new string[7];
for (int i = 0; i < 7; i++)
{
a[i] = date(System.DateTime.Now.AddDays(i));
}
string sql = " select 医生," + a[0] + "," + a[1] + "," + a[2] + "," + a[3] + "," + a[4] + "," + a[5] + "," + a[6] + " from test";
SqlCommand com = con1.CreateCommand();
com.CommandText = sql;
con1.Open();
dr = com.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
TemplateField customField = new TemplateField();
customField.ShowHeader = true;
customField.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[0],1);
customField.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",1);
GridView1.Columns.Add(customField);
TemplateField customField1 = new TemplateField();
customField1.ShowHeader = true;
customField1.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[1], 2);
customField1.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",2);
GridView1.Columns.Add(customField1);
TemplateField customField2 = new TemplateField();
customField2.ShowHeader = true;
customField2.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[2], 3);
customField2.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",3);
GridView1.Columns.Add(customField2);
TemplateField customField3 = new TemplateField();
customField3.ShowHeader = true;
customField3.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[3], 4);
customField3.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",4);
GridView1.Columns.Add(customField3);
TemplateField customField4 = new TemplateField();
customField4.ShowHeader = true;
customField4.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[4], 5);
customField4.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",5);
GridView1.Columns.Add(customField4);
TemplateField customField5 = new TemplateField();
customField5.ShowHeader = true;
customField5.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[5], 6);
customField5.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",6);
GridView1.Columns.Add(customField5);
TemplateField customField6 = new TemplateField();
customField6.ShowHeader = true;
customField6.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, a[6], 7);
customField6.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "",7);
GridView1.Columns.Add(customField6);
GridView1.DataSource = ds;
GridView1.DataBind();
con1.Close();
}
private string date(DateTime d)
{
string str = d.DayOfWeek.ToString();
string dates = "";
switch (str)
{
case "Monday": dates = "星期一"; break;
case "Tuesday": dates = "星期二"; break;
case "Wednesday": dates = "星期三"; break;
case "Thursday": dates = "星期四"; break;
case "Friday": dates = "星期五"; break;
case "Saturday": dates = "星期六"; break;
case "Sunday": dates = "星期日"; break;
}
return dates;
}
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
private int tid; public GridViewTemplate(DataControlRowType type, string colname,int id)
{
templateType = type;
columnName = colname;
tid = id;
} public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = columnName;
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
HyperLink HyperLink = new HyperLink();
HyperLink.ID = "HyperLink" + tid.ToString();
container.Controls.Add(HyperLink);
break;
default:
break;
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (dr.Read())
{
HyperLink hy1 = (HyperLink)e.Row.FindControl("HyperLink1");
hy1.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now) +"&name=" + dr[0].ToString() + "";
hy1.Text = dr[1].ToString();
HyperLink hy2 = (HyperLink)e.Row.FindControl("HyperLink2");
hy2.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(1)) + "&name=" + dr[0].ToString() + "";
hy2.Text = dr[2].ToString();
HyperLink hy3 = (HyperLink)e.Row.FindControl("HyperLink3");
hy3.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(2)) + "&name=" + dr[0].ToString() + "";
hy3.Text = dr[3].ToString();
HyperLink hy4 = (HyperLink)e.Row.FindControl("HyperLink4");
hy4.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(3)) + "&name=" + dr[0].ToString() + "";
hy4.Text = dr[4].ToString();
HyperLink hy5 = (HyperLink)e.Row.FindControl("HyperLink5");
hy5.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(4)) + "&name=" + dr[0].ToString() + "";
hy5.Text = dr[5].ToString();
HyperLink hy6 = (HyperLink)e.Row.FindControl("HyperLink6");
hy6.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(5)) + "&name=" + dr[0].ToString() + "";
hy6.Text = dr[6].ToString();
HyperLink hy7 = (HyperLink)e.Row.FindControl("HyperLink7");
hy7.NavigateUrl = "xxx.aspx?time=" + date(System.DateTime.Now.AddDays(6)) + "&name=" + dr[0].ToString() + "";
hy7.Text = dr[7].ToString();
}
}
}
}方法不好,但是能实现。我这里是正确的,你看看。我有事要出去了,有问题的话下午再说。