网。我想从 gridview 中获取选定的值到文本框中,我使用 sqlserver 数据库将数据显示到 gridview 中。在 ol 上没有其他链接对 me.plz 有帮助。
我的 BranchManage.aspx 页面的 aspx gridview 是:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False" DataSourceID="LinqDataSource_Branch">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="BranchName" HeaderText="BranchName" ReadOnly="True"
SortExpression="BranchName" />
<asp:BoundField DataField="CreateDate" HeaderText="CreateDate" ReadOnly="True"
SortExpression="CreateDate" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource_Branch" runat="server"
ContextTypeName="jemex.db.JemexDataContext" EntityTypeName=""
Select="new (BranchName, CreateDate)" TableName="Branches">
</asp:LinqDataSource>
-----这是我的 LoginController.cs 代码的一部分:
public ActionResult BranchManage(string submitButton, string branchname)
{
ViewBag.UserName = Session["username"];
if (Session["type"].ToString() == "Admin")
{
switch (submitButton)
{
case "Create Account":
return (Create_BranchAccount(branchname));
case "Update Account":
return (Update_BranchAccount());
case "Clear":
return (ClearBranch());
default:
return View();
}
}
else
{
return View("Login");
}
}
public ActionResult Create_BranchAccount(string branchname)
{
//DB.Execute_Qury("INSERT INTO Branches(BranchName,CreateDate,IsDeleted) VALUES (" +
branchname + "," + System.DateTime.Now + ",False)");
db1.R_Insert_Branch(branchname, System.DateTime.Now);
return View("BranchManage");
}
public ActionResult Update_BranchAccount()
{
SqlConnection con = new SqlConnection("Data Source=aaa-pc;Initial Catalog=logicnetclub_jemex;Integrated Security=True");
string strSQL = "Select * from Branches";
SqlDataAdapter dt = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
dt.Fill(ds, "UserDetail");
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
return View(ViewModel);
}
在 update_BranchAccount ,我如何获取 gridview 数据源?