2015-12-18 419 views
-1

enter image description here我想保存網格視圖文本框的值和兩個其他文本框,由用戶填寫Total MarksMarks Scored到數據庫我不知道如何傳回值textboxs數據的基礎上的點擊提交保存網格視圖文本框數據到數據庫

DB哪裏要保存的值是

Studentname  RegNo  TotalMarks Marksscored 
asdsa   22  125   22 

我的GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> 
    <Columns> 
     <asp:TemplateField HeaderText="Names"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtStudent_Name" runat="server" Text='<%# Eval("StudentFirstName") %>' ></asp:TextBox> 
      </ItemTemplate> 
      </asp:TemplateField> 
     <asp:TemplateField HeaderText="Register Number"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtreg_number" runat="server" Text='<%# Eval("StudentRegID") %>' ></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 

      <asp:TemplateField HeaderText="Total Marks"> 
      <ItemTemplate> 
       <asp:TextBox ID="txttotal_marks" runat="server" Text='' ></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Marks Scored"> 
      <ItemTemplate> 
       <asp:TextBox ID="txtmarks_scored" runat="server" Text='' ></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateField> 

    </Columns> 
</asp:GridView> 

回答

2
protected void Button1_Click(object sender, EventArgs e) 
{ 
GridView1.Visible = true; 
DataTable dt = new DataTable(); 
DataRow row = dt.NewRow(); 
for (int i = 0; i < GridView1.Rows.Count; i++) 
{ 
TextBox txtUsrId=(TextBox)GridView1.Rows[i].FindControl("Your textbox id"); 
string UserID = txtUsrId.Text; 
string q="insert into details (name) values('"+UserID+"')"; 
SqlCommand cmd = new SqlCommand(q, con); 
SqlDataAdapter da = new SqlDataAdapter(cmd); 
da.Fill(dt); 
} 
} 
+0

謝謝你的ans,但我不知道如何修改到我的gridview你可以plz幫我在那 – Shaik

+0

我試過這個代碼,通過添加我的網格視圖文本框的id,給了我一些錯誤我殼我上傳屏幕截圖? – Shaik

+0

你可以發佈我的錯誤 –

相關問題