自动生成colum false [英] auto generate colum false
本文介绍了自动生成colum false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test_Page.aspx.cs" Inherits="Grid_Data.Test_Page" %>
<!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>
<style type="text/css">
.style1
{
width: 113px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 61%;">
<tr>
<td class="style1">
<asp:Label ID="DeptLabel" runat="server" Text="Employee Name :"></asp:Label>
</td>
<td>
<asp:TextBox ID="nameTextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1" >
<asp:Label ID="EMPLabel" runat="server" Text="Emp_ID"></asp:Label>
:</td>
<td>
<asp:TextBox ID="empidTextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1" >
<asp:Label ID="DeptmntLabel" runat="server" Text="Department"></asp:Label>
:</td>
<td>
<asp:DropDownList ID="Deptdrop" runat="server">
<asp:ListItem>HR</asp:ListItem>
<asp:ListItem>ATM</asp:ListItem>
<asp:ListItem>R&D</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1" >
<asp:Label ID="DesigLabel" runat="server"
Text="Designation :"></asp:Label>
</td>
<td>
<asp:DropDownList ID="Desigdrop" runat="server">
<asp:ListItem>AVP</asp:ListItem>
<asp:ListItem>CTO</asp:ListItem>
<asp:ListItem>DCTO</asp:ListItem>
<asp:ListItem>First Executive Officer</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<asp:Label ID="dept" runat="server" Text="[dept]"></asp:Label>
<asp:Label ID="desLabel" runat="server" Text="[des]"></asp:Label>
<br />
<div>
<asp:GridView ID="showinfogrid" runat="server" AutoGenerateColumns="False"
Width="100%">
<Columns>
<asp:BoundField DataField ="Name" HeaderText ="Employee_Name" ReadOnly="true" />
<asp:BoundField DataField ="Employee_ID" HeaderText ="Emp_ID" ReadOnly="true"/>
<asp:BoundField DataField ="Department" HeaderText ="Department" ReadOnly="true"/>
<asp:BoundField DataField ="Designation" HeaderText ="Designation" ReadOnly="true"/>
</Columns>
</asp:GridView>
</div>
</div>
</form>
</body>
</html>
----------------------------------
----------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Grid_Data
{
public partial class Test_Page : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
dept.Text=Deptdrop.SelectedItem.Text;
desLabel.Text = Desigdrop.SelectedItem.Text;
DataTable dt = new DataTable();
this.showinfogrid.Visible = true;
dt.Columns.Add("Name");
dt.Columns.Add("Employee_ID");
dt.Columns.Add("Department");
dt.Columns.Add("Designation");
dt.Rows.Add(nameTextBox1.Text.Trim(), empidTextBox2.Text.Trim(), Deptdrop.SelectedItem.Text, Desigdrop.SelectedItem.Text);
showinfogrid.DataSource = dt;
showinfogrid.DataBind();
}
}
}
推荐答案
将gridview放入更新面板并将面板触发器设置为您的按钮。这是一篇关于 MSDN [ ^ ]帮您解决。
祝你好运,
OI
Put your gridview inside a update panel and set the panel trigger to your button. Here is an article on MSDN[^] to help you out.
Good luck,
OI
任何人告诉我如何在网格视图中每次添加行时单击按钮而不刷新页面但新行添加在上一行之后
Anyone tell me how i add row each time in the grid view when i click button without refreshing the page but the new row add after the previous row
这篇关于自动生成colum false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文