关于Asp.net GridVie的问题 [英] Question about Asp.net GridVie

查看:87
本文介绍了关于Asp.net GridVie的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了网格视图



I have used a grid view

<asp:GridView ID="GridView2" runat="server" Height="95%" Width="100%"   Visible="false"

        AllowPaging="True"  RowStyle-HorizontalAlign="Left"

BackColor="White"      GridLines="Horizontal" PageSize="8"

          BorderWidth="1px"    HeaderStyle-Font-Bold="true"



       AutoGenerateColumns="False" BorderColor="#E7E7FF"

        BorderStyle="None" CellPadding="3" style="margin-top: 0px"

          >
 <AlternatingRowStyle BackColor="#F7F7F7"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField ="StudentId" HeaderText="ID" ></asp:BoundField>
<asp:BoundField DataField ="name" HeaderText="Name" ></asp:BoundField>
<asp:BoundField DataField ="Attendance" HeaderText="Status" ></asp:BoundField>

<asp:TemplateField >
<ItemStyle HorizontalAlign ="Left" />
<HeaderStyle HorizontalAlign="Left"  />
<HeaderTemplate>
Edit 

</HeaderTemplate>
    
<ItemTemplate >
    <asp:LinkButton ID="edit"   runat="server" Font-Underline="true" CommandName="Edit"

                                                                    CommandArgument='<%#Eval("Id")%>'>Edit</asp:LinkButton>

</ItemTemplate>
</asp:TemplateField>




</Columns>
    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />

<HeaderStyle Font-Bold="True"  HorizontalAlign="Center"></HeaderStyle>

    <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Left" />

<RowStyle HorizontalAlign="Left" BackColor="#E7E7FF" ForeColor="#4A3C8C"></RowStyle>
    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
    <SortedAscendingCellStyle BackColor="#F4F4FD" />
    <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
    <SortedDescendingCellStyle BackColor="#D8D8F0" />
    <SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>









现在我要编辑ID,StudentName和ChekBox状态...当我点击编辑按钮时,我已经使用主键来编辑学生的状态...到编辑我使用的按钮

(Request.QueryString [ID])

当我点击编辑按钮时

学生证,学生姓名在文本框中可编辑...







Now I want to edit the the ID,StudentName and ChekBox status ...when i click on the edit button the i have used the primary key to edit the status of the student...to edit the button i have used the
(Request.QueryString["ID"])
When i click the edit button the
Student ID,Student Name becomes editable in the textboxes...

public void LoadAttendance()
  {
      int ID = Convert.ToInt32(Request.QueryString["ID"]);
      DataTable dt = new DataTable();
      dt = IITBAL.Assignments.GetFacultyAssignmentById(ID);
      ID.Text = dt.Rows[0]["Semester"].ToString();  //ID is the id of the textbox
      Student_Name.Text = dt.Rows[0]["CourseName"].ToString(); // student_name is the id of the tex box

  }



但问题是如何访问复选框的状态,复选框已选中或取消选中,其ID为.as.net中的ID为状态

推荐答案

如果您使用位数据类型然后按照此代码

if your using bit data type then follw this code
CheckBox1.Checked = Convert.ToBoolean(dt.Rows[0]["Attendance"]); 



如果您使用的是比较数据类型varchar或其他一些事情,请参阅此示例



示例:



我们将复选框值存储为varchar数据类型

如果选中复选框,那么我们将strore为是 否则我们将存储为否


if you are using rather then bit datatype varchar or some thing else follw this example

Example:

we store the check box value as varchar data type
if checkbox checked then we will strore as "Yes" else we will store as "No"

if(Convert.toString(dt.Rows[0]["Attendance"])=="Yes")
CheckBox1.Checked =true;
else if(Convert.toString(dt.Rows[0]["Attendance"])=="No")
CheckBox1.Checked =false;







注意:在转换中尝试使用Convert.toString()请避免使用ToString()




Note: In Convertions try to use Convert.toString() please avoid use ToString()


这篇关于关于Asp.net GridVie的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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