如何在GridView中处理多个命令字段 [英] How to handle more than one command fields in gridview
本文介绍了如何在GridView中处理多个命令字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在gridview中处理多个命令域.
我的aspx代码是:
Hi,
How to handle multiple commandfields in gridview.
My aspx code is:
<asp:GridView ID="GridOracle" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="DIS_CHAPTER_ID" OnSelectedIndexChanged="GridOracle_SelectedIndexChanged"
BackColor="#CCCCCC" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" ForeColor="Black">
<%-- BorderColor=#999999--%>
<Columns>
<asp:BoundField DataField="SEC_NAME" HeaderText="Section Name" ReadOnly="True" ItemStyle-HorizontalAlign="Left"
ItemStyle-Font-Bold="true" ItemStyle-VerticalAlign="Middle">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Font-Bold="True"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="CHAPTER_NAME" HeaderText="CourseName" ReadOnly="True"
ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Middle">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Duration" HeaderText="Duration" ItemStyle-HorizontalAlign="Left"
ItemStyle-VerticalAlign="Middle">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
</asp:BoundField>
<asp:CommandField CausesValidation="False" InsertVisible="False" ShowCancelButton="False"
ButtonType="Image" ShowSelectButton="True" HeaderText="Material" ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle" SelectImageUrl="~/Content/Images/PDFLogo.png">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
</asp:CommandField>
<asp:CommandField CausesValidation="False" InsertVisible="False" ShowCancelButton="False"
ButtonType="Image" ShowSelectButton="True" HeaderText="Material1" ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle" SelectImageUrl="~/Content/Images/PDFLogo.png">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
</asp:CommandField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="Black" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
我的Commandpx的aspx.cs代码
My aspx.cs code for commandfield
protected void GridOracle_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (GridOracle.SelectedIndex > -1)
{
this.Id = Convert.ToInt32(GridOracle.DataKeys[GridOracle.SelectedIndex].Value);
string _FName = "select FILE_NAME from OM_DOC_ALL where DIS_CHAPTER_ID = " + Id;
string _FileName = (string)SqlHelper.ExecuteScalar(strConn, CommandType.Text, _FName);
string FileName = "~/Downloads/OracleMaterial/" + _FileName + ".pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
WebClient client = new WebClient();
string pdfPath = Server.MapPath("../Downloads/OracleMaterial/" + _FileName + ".pdf");
Byte[] buffer = client.DownloadData(pdfPath);
BinaryWriter bw = new BinaryWriter(Response.OutputStream);
bw.Write(buffer);
bw.Close();
Response.ContentType = "application/pdf";
Response.Flush();
Response.Close();
}
else
{
//Clear Controls
}
}
catch (Exception ex)
{
ErrorHandling.ErrorLog("PageLoad: ExploreJobs.aspx.cs , Error : " + ex.Message);
}
}
如何编写2个命令域(Material& Material1的标题文本)代码.
How to write 2 commandfields(Header text of Material & Material1) code.
推荐答案
只需将其从未答复列表中删除即可. OP说他得到了解决方案.
Just to remove it from unanswered list. OP says'' he got the solution.
这篇关于如何在GridView中处理多个命令字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文