在ASP.Net中的GridView中只读一列 [英] Making a column readonly in GridView in ASP.Net

查看:103
本文介绍了在ASP.Net中的GridView中只读一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个编辑sql数据库的网页。但是在gridview中我想只读一个clomn,当我这样做时更新不起作用。



下面是代码:





<%@ Page Language =C#AutoEventWireup =trueCodeBehind =WebForm2.aspx.csInherits =Test.WebForm2%>



<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/ xhtml1 / DTD / xhtml1-transitional.dtd>



< html xmlns =http://www.w3.org/1999/xhtml>

< head runat =server>

< title>< / title>

< / head>

< body>

< form id =form1runat =server>

Hi,

I have made a webpage that will edit the sql database. But in the gridview I want to make a clomn readonly and when I do so Update is not working.

Below is the code:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Test.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">



$ / b $ b $ / b
< asp:TextBox ID =TextBox1runat =serverBackColor =#3877C5字体粗体=真

字体名称=Calibri字体大小=X大ForeColor =白色宽度=924px>软件错配报告







< asp:SqlDataSource ID =供应商runat =server ConnectionString =Data Source = 10.128.32.190; Initial Catalog = SYBIDEV; Integrated Security = True



SelectCommand =SELECT DISTINCT Vendor FROM tblFactSoftwareStg>











< asp:GridView ID = GridView1runat =serverAllowPaging =True

AllowSorting =TrueAutoGenerateColumns =FalseCellPadding =4

DataSourceID =SIForeColor =#333333GridLines =无

AutoGenerateEditButton =True

onselectedindexchanged =GridView1_SelectedIndexChangedPageSize =20

字体-Names =Calibri>

< alternatingrowstyle backcolor =Whitefont-bold =Falsefont-names =Calibri>

字体 - 大小=的Medi嗯/>

< columns> < asp:BoundField DataField =VendorHeaderText =Vendor

SortExpression =VendorReadOnly =True/>

< asp:BoundField DataField =SoftwareNameHeaderText =SoftwareName

SortExpression =SoftwareName/>

< asp:BoundField DataField =VersionHeaderText =Version

SortExpression =Version/>

< asp:BoundField DataField =LicenseTypeHeaderText =LicenseType

SortExpression =LicenseType />

< asp:BoundField DataField =GenericSoftwareName

HeaderText =GenericSoftwareNameSortExpression =GenericSoftwareName/>

< editrowstyle backcolor =#99CCFF>

< footerstyle backcolor =#507CD1font-bold =Trueforecolor =White>

< HeaderStyle BackColor =#507CD1Font-Bold =TrueForeColor =White/>

< pagerstyle backcolor =#2461BFforecolor =Whitehorizo​​ntalalign =Center> ;

< rowstyle backcolor =#EFF3FB>

< SelectedRowStyle BackColor =#D1DDF1Font-Bold =TrueForeColor =#333333 />

< sortedascendingcellstyle backcolor =#F5F7FB>

< sortedascendingheaderstyle backcolor =#6D95E1>

< ; sorteddescendingcellstyle backcolor =#E9EBEF>

< sorteddescendingheaderstyle backcolor =#4870BE>



< asp:SqlDataSource ID =SIrunat =server

ConnectionString =数据源= 10.128.32.190;初始目录= SYBIDEV;集成安全性=真

ProviderName =System .Data.SqlClientSelectCommand =选择不同的Vendor,SoftwareName,Version,LicenseType,GenericSoft wareName来自tblFactSoftwareStg,其中(GenericSoftwareName ='NA'或GenericSoftwareName为null或LicenseType ='NA'或LicenseType为null)







UpdateCommand =exec SCCM_Test @ Vendor = @ Vendor,@ SoftwareName = @ SoftwareName,@ Version = @ Version,@ LicenseType = @ LicenseType,@ GenericSoftwareName = @ GenericSoftwareName>

< updateparameters>

< asp:参数名称=供应商/>

< asp:参数名称=SoftwareName/>

< asp:参数名称=版本/>

< asp:参数名称=LicenseType/>

< ; asp:参数名称=GenericSoftwareName/>













<asp:TextBox ID="TextBox1" runat="server" BackColor="#3877C5" Font-Bold="True"
Font-Names="Calibri" Font-Size="X-Large" ForeColor="White" Width="924px"> Software MisMatch Report



<asp:SqlDataSource ID="Vendor" runat="server" ConnectionString="Data Source=10.128.32.190;Initial Catalog=SYBIDEV;Integrated Security=True"

SelectCommand="SELECT DISTINCT Vendor FROM tblFactSoftwareStg">






<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SI" ForeColor="#333333" GridLines="None"
AutoGenerateEditButton="True"
onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="20"
Font-Names="Calibri">
<alternatingrowstyle backcolor="White" font-bold="False" font-names="Calibri">
Font-Size="Medium" />
<columns> <asp:BoundField DataField="Vendor" HeaderText="Vendor"
SortExpression="Vendor" ReadOnly="True" />
<asp:BoundField DataField="SoftwareName" HeaderText="SoftwareName"
SortExpression="SoftwareName" />
<asp:BoundField DataField="Version" HeaderText="Version"
SortExpression="Version" />
<asp:BoundField DataField="LicenseType" HeaderText="LicenseType"
SortExpression="LicenseType" />
<asp:BoundField DataField="GenericSoftwareName"
HeaderText="GenericSoftwareName" SortExpression="GenericSoftwareName" />
<editrowstyle backcolor="#99CCFF">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center">
<rowstyle backcolor="#EFF3FB">
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<sortedascendingcellstyle backcolor="#F5F7FB">
<sortedascendingheaderstyle backcolor="#6D95E1">
<sorteddescendingcellstyle backcolor="#E9EBEF">
<sorteddescendingheaderstyle backcolor="#4870BE">

<asp:SqlDataSource ID="SI" runat="server"
ConnectionString="Data Source=10.128.32.190;Initial Catalog=SYBIDEV;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="select distinct Vendor,SoftwareName,Version,LicenseType,GenericSoftwareName from tblFactSoftwareStg where (GenericSoftwareName='NA' or GenericSoftwareName is null or LicenseType='NA' or LicenseType is null) "



UpdateCommand="exec SCCM_Test @Vendor=@Vendor,@SoftwareName=@SoftwareName,@Version=@Version,@LicenseType=@LicenseType,@GenericSoftwareName=@GenericSoftwareName">
<updateparameters>
<asp:Parameter Name="Vendor" />
<asp:Parameter Name="SoftwareName" />
<asp:Parameter Name="Version" />
<asp:Parameter Name="LicenseType" />
<asp:Parameter Name="GenericSoftwareName" />






< / form>

< / body>

< / html>


</form>
</body>
</html>

推荐答案

请参阅此处......



CP链接

插入编辑更新和删除数据
Refer Here...

CP link
Insert Edit update-and-delete-data


这篇关于在ASP.Net中的GridView中只读一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆