如何做到datagrid根据数据自动生成下拉条! 如题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先拖一个下拉条,加载上数据然后可以dgvStockPlan.controls.Add(zfComboBox1);//zfComboBox1为下拉框,dgvStockPlan是gridView Rectangle rect = this.dgvStockPlan.GetCellDisplayRectangle(this.dgvStockPlan.CurrentCell.ColumnIndex, this.dgvStockPlan.CurrentCell.RowIndex, false); this.zfComboBox1.Left = rect.Left; this.zfComboBox1.Top = rect.Top; this.zfComboBox1.Width = rect.Width; this.zfComboBox1.Height = rect.Height; this.zfComboBox1.Visible = true;在gridView里重新绘制它 首先我要说的是在WEB中好像真的是没有datagrid控件。常用的我只知道3个。GirdView,Repeater,DataList这3个都能实现根据数据下拉 Datagrid 外面加个Div就可以了<div style="width:1024px;height:300px;overflow:auto;">....DataGrid</div>--------再不行的话,你就要自己重写一个自定义的DataGrid了。前面这个方法我个人认为是最简单的。 这个是让表头不动的HTML原代码。因为DataGrid这个控件我不常在vs2008中用,所有到时候你自己Code一下就行<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <style type="text/css"> <!-- body { background: #FFF; color: #000; font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif; margin: 10px; padding: 0 } table, td, a { color: #000; font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif } .td { nowrap:’’true’’; } div.tableContainer { border: 1px solid #963; height: 185px; overflow: auto; width: 100%; } /* WinIE 6.x needs to re-account for it’’s scrollbar. Give it some padding */ \html div.tableContainer/* */ { padding: 0 16px 0 0 } /* define width of table. IE browsers only */ /* if width is set to 100%, you can remove the width */ /* property from div.tableContainer and have the div scale */ div.tableContainer table { float: left; width: 100% } /* WinIE 6.x needs to re-account for padding. Give it a negative margin */ \html div.tableContainer table/* */ { margin: 0 -16px 0 0 } /* set table header to a fixed position. WinIE 6.x only */ /* In WinIE 6.x, any element with a position property set to relative and is a child of */ /* an element that has an overflow property set, the relative value translates into fixed. */ /* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */ thead.fixedHeader tr { position: relative; /* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */ top: expression(document.getElementById("tableContainer").scrollTop) } /* make the TH elements pretty */ thead.fixedHeader th { background: #C96; border-left: 1px solid #EB8; border-right: 1px solid #B74; border-top: 1px solid #EB8; font-weight: normal; padding: 4px 3px; text-align: center } /* make the A elements pretty. makes for nice clickable headers */ thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited { color: #FFF; display: block; text-decoration: none; width: 100% } /* make the A elements pretty. makes for nice clickable headers */ /* WARNING: swapping the background on hover may cause problems in WinIE 6.x */ thead.fixedHeader a:hover { color: #FFF; display: block; text-decoration: underline; width: 100% } /* make TD elements pretty. Provide alternating classes for striping the table */ /* http://www.alistapart.com/articles/zebratables/ */ tbody.scrollContent td, tbody.scrollContent tr.normalRow td { background: #FFF; border-bottom: 1px solid #EEE; border-left: 1px solid #EEE; border-right: 1px solid #AAA; border-top: 1px solid #AAA; padding: 2px 3px } tbody.scrollContent tr.alternateRow td { background: #EEE; border-bottom: 1px solid #EEE; border-left: 1px solid #EEE; border-right: 1px solid #AAA; border-top: 1px solid #AAA; padding: 2px 3px } --> </style> </head><body> <div id="tableContainer" class="tableContainer" style="width:900px;"> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable"> <thead class="fixedHeader"> <tr> <th><a href="#">Header 1</a></th> <th><a href="#">Header 2</a></th> <th><a href="#">Header 3</a></th> <th><a href="#">Header 4</a></th> <th><a href="#">Header 5</a></th> <th><a href="#">Header 6</a></th> <th><a href="#">Header 7</a></th> </tr> </thead> <tbody class="scrollContent"> <tr> <td>Cell Content 1</td> <td>Cell Content 2</td> <td>Cell Content 3</td> <td>Cell Content 4</td> <td>Cell Content 5</td> <td>Cell Content 6</td> <td>Cell Content 7</td> </tr> <tr> <td>More Cell Content 1</td> <td>More Cell Content 2</td> <td>More Cell Content 3</td> <td>More Cell Content 4</td> <td>More Cell Content 5</td> <td>More Cell Content 6</td> <td>More Cell Content 7</td> </tr> <tr> <td nowrap>Even More Cell Content 1 Even More Cell Content Even More Cell Content </td> <td nowrap>Even More Cell Content 2</td> <td nowrap>Even More Cell Content 3</td> <td nowrap>Even More Cell Content 4</td> <td nowrap>Even More Cell Content 5</td> <td nowrap>Even More Cell Content 6</td> <td nowrap>Even More Cell Content 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> <tr> <td>And Repeat 1</td> <td>And Repeat 2</td> <td>And Repeat 3</td> <td>And Repeat 4</td> <td>And Repeat 5</td> <td>And Repeat 6</td> <td>And Repeat 7</td> </tr> </tbody> </table> </div> </body></html> 一般我都是用GridView+DropDownList来实现。如果你是初学者。建议你用SqlDataSource控件来配置数据源。实现起来很简单。GridView里添加类型为TemplateField列。代码如下:<asp:GridView ID="GridView1" runat="server"> <asp:TemplateField HeaderText="【下拉条】页眉名称"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataSource='【绑定的SqlDataSource数据源】这里可以在【设计】模式下手动添加'> </asp:DropDownList> </ItemTemplate> </asp:TemplateField></asp:GridView>不知道您看懂了没 意思是跟WinFORM的DATAGRIDVIEW样的数据多了直接由个下拉条? 求Shell_NotifyIcon详细用法 关于 multi dictionary? 提取网页正文? 关于多线程访问控件的问题 不知道是第几次问这个问题了....期待中.. nVS2005类中namespace问题 DataGridViewComboBoxColumn列在添加行时报错的问题 关于显微镜下图片的处理 急,C#使用Excel 请问; C#中有没有关于ftp的协议? C#如何将picturecbox中的图片保存到本地 怎样在控制台中嵌入图片
然后可以
dgvStockPlan.controls.Add(zfComboBox1);//zfComboBox1为下拉框,dgvStockPlan是gridView Rectangle rect = this.dgvStockPlan.GetCellDisplayRectangle(this.dgvStockPlan.CurrentCell.ColumnIndex, this.dgvStockPlan.CurrentCell.RowIndex, false);
this.zfComboBox1.Left = rect.Left;
this.zfComboBox1.Top = rect.Top;
this.zfComboBox1.Width = rect.Width;
this.zfComboBox1.Height = rect.Height;
this.zfComboBox1.Visible = true;
在gridView里重新绘制它
这3个都能实现根据数据下拉
....DataGrid
</div>--------
再不行的话,你就要自己重写一个自定义的DataGrid了。前面这个方法我个人认为是最简单的。
<style type="text/css">
<!--
body {
background: #FFF;
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
margin: 10px;
padding: 0
} table, td, a {
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
} .td
{
nowrap:’’true’’;
} div.tableContainer {
border: 1px solid #963;
height: 185px;
overflow: auto;
width: 100%;
} /* WinIE 6.x needs to re-account for it’’s scrollbar. Give it some padding */
\html div.tableContainer/* */ {
padding: 0 16px 0 0
}
/* define width of table. IE browsers only */
/* if width is set to 100%, you can remove the width */
/* property from div.tableContainer and have the div scale */
div.tableContainer table {
float: left;
width: 100%
} /* WinIE 6.x needs to re-account for padding. Give it a negative margin */
\html div.tableContainer table/* */ {
margin: 0 -16px 0 0
}
/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative;
/* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */
top: expression(document.getElementById("tableContainer").scrollTop)
} /* make the TH elements pretty */
thead.fixedHeader th {
background: #C96;
border-left: 1px solid #EB8;
border-right: 1px solid #B74;
border-top: 1px solid #EB8;
font-weight: normal;
padding: 4px 3px;
text-align: center
} /* make the A elements pretty. makes for nice clickable headers */
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
color: #FFF;
display: block;
text-decoration: none;
width: 100%
} /* make the A elements pretty. makes for nice clickable headers */
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x */
thead.fixedHeader a:hover {
color: #FFF;
display: block;
text-decoration: underline;
width: 100%
} /* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/ */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
background: #FFF;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
} tbody.scrollContent tr.alternateRow td {
background: #EEE;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
}
-->
</style>
</head><body>
<div id="tableContainer" class="tableContainer" style="width:900px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
<thead class="fixedHeader">
<tr>
<th><a href="#">Header 1</a></th>
<th><a href="#">Header 2</a></th>
<th><a href="#">Header 3</a></th>
<th><a href="#">Header 4</a></th>
<th><a href="#">Header 5</a></th>
<th><a href="#">Header 6</a></th>
<th><a href="#">Header 7</a></th>
</tr>
</thead>
<tbody class="scrollContent">
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
<td>Cell Content 4</td>
<td>Cell Content 5</td>
<td>Cell Content 6</td>
<td>Cell Content 7</td>
</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
<td>More Cell Content 4</td>
<td>More Cell Content 5</td>
<td>More Cell Content 6</td>
<td>More Cell Content 7</td>
</tr>
<tr>
<td nowrap>Even More Cell Content 1 Even More Cell Content Even More Cell Content </td>
<td nowrap>Even More Cell Content 2</td>
<td nowrap>Even More Cell Content 3</td>
<td nowrap>Even More Cell Content 4</td>
<td nowrap>Even More Cell Content 5</td>
<td nowrap>Even More Cell Content 6</td>
<td nowrap>Even More Cell Content 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr> <tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr> <tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
<td>And Repeat 4</td>
<td>And Repeat 5</td>
<td>And Repeat 6</td>
<td>And Repeat 7</td>
</tr>
</tbody>
</table>
</div>
</body></html>
如果你是初学者。建议你用SqlDataSource控件来配置数据源。实现起来很简单。
GridView里添加类型为TemplateField列。
代码如下:
<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="【下拉条】页眉名称">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource='【绑定的SqlDataSource数据源】这里可以在【设计】模式下手动添加'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>不知道您看懂了没