我有以下代码.我没有在gridview中定义任何边界字段.我正在使用我的aspx.cs文件中的sql查询来检索数据.是否可以调整每列0,1,2的宽度?我有什么办法可以研究吗?我尝试了很多方法,但它仍然无法正常工作.请帮忙!
<asp:GridView ID="surgicalGridView" runat="server"
CaptionAlign="Top" HorizontalAlign="Justify"
DataKeyNames="id" onselectedindexchanged="surgicalGridView_SelectedIndexChanged"
ToolTip="Excel File Download Tool" CellPadding="4" ForeColor="#333333"
GridLines="None" Width="854px">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Download"
ControlStyle-ForeColor="Blue">
<ControlStyle ForeColor="Blue"></ControlStyle>
</asp:CommandField>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<br />
Run Code Online (Sandbox Code Playgroud) 当OnItemUpdated被解雇时,我不能为我的生活找到答案.我一直在使用ASP.NET来试图学习它,所以你在这段代码中看到的一些东西可能是故意做的(所以我可以更好地理解幕后发生的事情)
基本上,我有一个GridView,它是使用formview作为细节的主控件.
这是SelectedIndexChanged方法GridView
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
var context = new DataAccessLayer.SafetyEntities();
var se = (from c in context.Employees
where c.EID == (long)GridView1.SelectedDataKey.Value
select c).ToList();
FormView1.DataSource = se;
FormView1.DataKeyNames = new string[] { "EID" };
FormView1.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
这样工作正常,它会在表单中显示所选的详细信息以进行编辑.这是formview看起来像:
<asp:FormView ID="FormView1" runat="server" DefaultMode="Edit" OnItemUpdating = "FormView1_ItemUpdating" OnItemUpdated="BLAH">
<ItemTemplate>
Select an employee!
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<th>Name:
</th>
<td>
<asp:TextBox runat="server" ID ="NameEdit" Text='<%#Bind("Name") %>' />
</td>
<br />
</tr>
<tr>
<th>Manager:
</th>
<td> …Run Code Online (Sandbox Code Playgroud)